| 516 | } |
| 517 | |
| 518 | func getRunCommand() cli.Command { |
| 519 | return cli.Command{ |
| 520 | Name: "run", |
| 521 | ShortName: "run", |
| 522 | Usage: "Run Gohan script Code", |
| 523 | Description: ` |
| 524 | Run gohan script code.`, |
| 525 | Flags: []cli.Flag{ |
| 526 | cli.StringFlag{Name: "config-file,c", Value: defaultConfigFile, Usage: "config file path"}, |
| 527 | cli.StringFlag{Name: "args,a", Value: "", Usage: "arguments"}, |
| 528 | }, |
| 529 | Action: func(c *cli.Context) { |
| 530 | src := c.Args()[0] |
| 531 | vm := gohanscript.NewVM() |
| 532 | |
| 533 | args := []interface{}{} |
| 534 | flags := map[string]interface{}{} |
| 535 | for _, arg := range c.Args()[1:] { |
| 536 | if strings.Contains(arg, "=") { |
| 537 | kv := strings.Split(arg, "=") |
| 538 | flags[kv[0]] = kv[1] |
| 539 | } else { |
| 540 | args = append(args, arg) |
| 541 | } |
| 542 | } |
| 543 | vm.Context.Set("args", args) |
| 544 | vm.Context.Set("flags", flags) |
| 545 | configFile := c.String("config-file") |
| 546 | loadConfig(configFile) |
| 547 | _, err := vm.RunFile(src) |
| 548 | if err != nil { |
| 549 | fmt.Println(err) |
| 550 | os.Exit(1) |
| 551 | return |
| 552 | } |
| 553 | }, |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | func getTestCommand() cli.Command { |
| 558 | return cli.Command{ |