Beispiel #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
}
Beispiel #2
0
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
}
Beispiel #3
0
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()
	}
}
Beispiel #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
}
Beispiel #5
0
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)
	}
}
Beispiel #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
}