func registerPasswordCommandParamsWithPassgoRegistrar(passgo *app.App) *app.App { pLength := password.NewLength() pLength.Set("10") passgo.Register(pLength.Name(), pLength) noSymbols := password.NewNoSymbols() passgo.Register(noSymbols.Name(), noSymbols) return passgo }
func thenRegisterCommandToExecute(passgo *app.App) func(*flag.Flag) { fn := func(f *flag.Flag) { currentFlag := f.Value.(PassgoFlag) currentFlagIsOf := cmd.PassgoCommands[currentFlag.Name()] switch currentFlagIsOf.(type) { case cmd.Command: commandToExecute := currentFlagIsOf passgo.Register("commandToExecute", commandToExecute) } } return fn }
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 }
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 registerGenerateCommandFlagsWithPassgoRegistrar(passgo *app.App) *app.App { url := generate.NewUrl() url.Set("https://cip.li") passgo.Register(url.Name(), url) userName := generate.NewUserName() userName.Set("zap_rowsdower") passgo.Register(userName.Name(), userName) pLength := password.NewLength() pLength.Set("10") passgo.Register(pLength.Name(), pLength) noSymbols := password.NewNoSymbols() passgo.Register(noSymbols.Name(), noSymbols) return passgo }