-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (61 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"os"
"github.com/sic-xe/sicer/pkg/simulator"
)
var (
debugFlag bool
helpFlag bool
simCmd = flag.NewFlagSet("sim", flag.ExitOnError)
simInFlag = simCmd.String("i", "", "Input object file path (.obj) [required]")
)
func main() {
if len(os.Args) < 2 || os.Args[1] == "-h" {
help()
os.Exit(0)
}
for _, fs := range []*flag.FlagSet{simCmd} {
fs.BoolVar(&debugFlag, "d", false, "Show debug info")
fs.BoolVar(&helpFlag, "h", false, "Show available flags")
}
switch os.Args[1] {
case "sim":
simCmd.Parse(os.Args[2:])
runSimulator()
default:
fmt.Printf("Unknown subcommand '%s'\n\n", os.Args[1])
help()
os.Exit(1)
}
}
func help() {
fmt.Println(`Usage: sicer <subcommand> [flags]
Subcommands:
sim Run object code in the simulator
Global flags:
-d Show debug info
-h Show available flags`)
}
func runSimulator() {
// Print usage info if requested
if helpFlag {
simCmd.Usage()
os.Exit(0)
}
// Check if an input file was provided
if simInFlag == nil || *simInFlag == "" {
fmt.Printf("No input file provided!\n\n")
simCmd.Usage()
os.Exit(1)
}
// Check if the input file exists
inFile := *simInFlag
if _, err := os.Stat(inFile); os.IsNotExist(err) {
fmt.Printf("Input file %s does not exist!\n\n", inFile)
simCmd.Usage()
os.Exit(1)
}
simulator.Start(debugFlag, inFile)
}