Example #1
0
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
}
Example #2
0
File: cli.go Project: sdaros/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
}
Example #3
0
File: cli.go Project: sdaros/passgo
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()
	}
}
Example #4
0
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
}
Example #5
0
File: cli.go Project: sdaros/passgo
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)
	}
}
Example #6
0
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
}