feat: use switch-case to match subcommands
@@ -2,7 +2,6 @@ package main
import (
"errors"
- "strings"
"github.com/anz-bank/sysl/pkg/mod"
"gopkg.in/alecthomas/kingpin.v2"
@@ -12,23 +11,27 @@ type modCmd struct {
modName string
}
+var (
+ initCmd *kingpin.CmdClause
+)
+
func (m *modCmd) Name() string { return "mod" }
func (m *modCmd) MaxSyslModule() int { return 0 }
func (m *modCmd) Configure(app *kingpin.Application) *kingpin.CmdClause {
- cmd := app.Command(m.Name(), "Configure sysl module system")
- initCmd := cmd.Command("init", "sysl module init command")
- initCmd.Arg("mod name", "Name of sysl module").Required().StringVar(&m.modName)
+ cmd := app.Command(m.Name(), "provides access to operations on Sysl modules")
+ initCmd = cmd.Command("init", "initializes and writes a new go.mod to the current directory")
+ initCmd.Arg("name", "path of current sysl module").StringVar(&m.modName)
return cmd
}
func (m *modCmd) Execute(args ExecuteArgs) error {
// subcommands are somewhat funky using the cmd_runner
- subcommand := strings.Split(args.Command, " ")[1]
- if subcommand == "init" {
+ switch args.Command {
+ case initCmd.FullCommand():
return mod.SyslModInit(m.modName, args.Logger)
- }
-
+ default:
return errors.New("command not recognized")
}
+}
