func registerCliFlagsWithPassgoRegistrar(passgo *app.App, flagSet *flag.FlagSet) { passgo.Register("passgoFlags", PassgoFlags) flagsToParse := passgo.Lookup("passgoFlags").([]PassgoFlag) for _, flag := range flagsToParse { flagSet.Var(flag, flag.Name(), flag.Usage()) passgo.Register(flag.Name(), flag) } }
func Parse(passgo *app.App) { flagSet := flag.NewFlagSet("passgoFlags", flag.ExitOnError) setUsage(flagSet) registerCliFlagsWithPassgoRegistrar(passgo, flagSet) flagSet.Parse(os.Args[1:]) flagSet.Visit(thenRegisterCommandToExecute(passgo)) if passgo.Lookup("commandToExecute") == nil { // No executable command was provided by the user // on the command line; print Usage. flagSet.Usage() } }
func processInput(passgo *app.App) error { cli.Parse(passgo) command := passgo.Lookup("commandToExecute").(cmd.Command) if err := command.ApplyCommandParamsFrom(passgo); err != nil { return err } execute := command.ExecuteFn() cmdResult, err := execute() if err != nil { return err } _, err = displayOutputTo(os.Stdout, cmdResult) if err != nil { return err } return nil }