Get commands provided by spread
(spread *cli.SpreadCli)
| 25 | |
| 26 | // Get commands provided by spread |
| 27 | func commands(spread *cli.SpreadCli) []clilib.Command { |
| 28 | cmds := []clilib.Command{} |
| 29 | |
| 30 | cliType := reflect.ValueOf(spread) |
| 31 | for i := 0; i < cliType.NumMethod(); i++ { |
| 32 | cmd := cliType.Method(i) |
| 33 | |
| 34 | // check that is returning command |
| 35 | cmdType := cmd.Type() |
| 36 | if cmdType.NumOut() == 1 && cmdType.Out(0) == reflect.TypeOf(new(clilib.Command)) { |
| 37 | cmdFn := cmd.Interface().(func() *clilib.Command) |
| 38 | command := cmdFn() |
| 39 | if command != nil { |
| 40 | cmds = append(cmds, *command) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | return cmds |
| 45 | } |
| 46 | |
| 47 | func app() *clilib.App { |
| 48 | app := clilib.NewApp() |