-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
51 lines (42 loc) · 998 Bytes
/
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
package main
import (
"flag"
"github.com/pacolang/paco/log"
"github.com/pacolang/paco/runtime"
"io/ioutil"
"os"
)
func main() {
// Build command with its flags
buildCommand := flag.NewFlagSet("build", flag.ExitOnError)
buildFile := buildCommand.String("f", "", "Specifies the file to execute")
buildName := buildCommand.String("o", "main", "Specifies the name of the executable")
// Gets the executable name
flag.Parse()
if len(os.Args) < 2 {
log.Errorf("You need to specify a command.")
}
// Commands
switch os.Args[1] {
case "build":
err := buildCommand.Parse(os.Args[2:])
if err != nil {
panic(err)
}
build(*buildFile, *buildName)
break
}
}
// build builds a specified paco file
func build(file, name string) {
// Check if the file is specified
if file == "" {
log.Errorf("You need to specify a file to build.")
}
// Read the given file
bytes, err := ioutil.ReadFile(file)
if err != nil {
log.Errorf(err)
}
runtime.Run(string(bytes), name)
}