You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/cmd/root.go

53 lines
1.0 KiB

package cmd
import (
"fmt"
"os"
"time"
"github.com/spf13/cobra"
"git.jfdev.de/JonasFranzDEV/hal/hal"
"git.jfdev.de/JonasFranzDEV/hal/parser"
)
func Execute() {
if err := rootCommand.Execute(); err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
}
var rootCommand = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "hal",
RunE: runRootCommand,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
startTime = time.Now()
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
totalTime := time.Since(startTime)
fmt.Printf("Total execution time: %v\n", totalTime)
},
}
var debug bool
var startTime time.Time
func init() {
rootCommand.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable debug mode")
}
func runRootCommand(cmd *cobra.Command, args []string) error {
filename := args[0]
program, err := parser.ParseFile(filename)
if err != nil {
return err
}
module, err := hal.NewHALModule(program, 256, 2, debug)
if err != nil {
return err
}
return module.Run()
}