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

55 lines
1011 B

package cmd
import (
"bufio"
"fmt"
"os"
"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,
}
func init() {
rootCommand.Flags().BoolP("debug", "d", false, "Enable debug mode")
}
func runRootCommand(cmd *cobra.Command, args []string) error {
filename := args[0]
if stats, err := os.Stat(filename); err != nil || stats.IsDir() {
return err
}
file, err := os.Open(filename)
if err != nil {
return err
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var input []string
for scanner.Scan() {
input = append(input, scanner.Text())
}
if err := file.Close(); err != nil {
return err
}
program, err := parser.ParseProgram(input)
if err != nil {
return err
}
hal.NewHALModule(program, 256)
return nil
}