-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
40 lines (37 loc) · 780 Bytes
/
action.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
package bcli
import (
"fmt"
"io/ioutil"
"os"
bf "github.com/ryomak/brainfuck-go"
"github.com/urfave/cli"
)
func run(c *cli.Context) {
config, err := bf.LoadConfig(c.String("config"))
if err != nil {
if c.String("config") != "" {
fmt.Printf("cannot load config : %s \n", c.String("config"))
os.Exit(0)
}
if c.Bool("d"){
config = bf.DefaultConfig()
}else{
config = bf.GokuConfig()
}
}
if len(c.Args()) == 0 {
fmt.Printf("no files listed")
os.Exit(0)
}
src := []byte{}
for _, v := range c.Args() {
inputSrc, err := ioutil.ReadFile(v)
if err != nil {
fmt.Printf("cannot read %s", v)
os.Exit(0)
}
src = append(src, inputSrc...)
}
state := bf.InitState(string(src), config.GetCommands(), c.Int("max"))
state.Start()
}