Ejemplo n.º 1
0
//getFlagValues returns the list of requirements needed to run a command.
func getFlagValues(command command.Command, cmdFlags []string, sessionObject session.Session, args []string) []string {
	var i = 0
	//If flag parsing is disabled
	if command.Metadata().SkipFlagParsing {
		flags := command.Metadata().Flags
		// Prompt for values for each flag
		flagValues := make([]string, len(flags), len(flags))
		for n := 0; n < len(flags); n++ {
			if flag, ok := flags[n].(cli.StringFlag); ok {
				if flag.Usage != "password" {
					fmt.Print(flag.Usage + " > ")
					fmt.Scanf("%s", &flagValues[i])
					if flag.Usage == "userName" {
						sessionObject.UserName = flagValues[i]
					}
					i++
				} else {
					flagValues[i] = password.AskForPassword("Password")
					i++
				}
			}
		}
		return flagValues
	} else {
		isMatch, flagValues := matchArgAndFlags(cmdFlags, args[1:], sessionObject)
		if isMatch {
			return flagValues
		} else {
			return nil
		}
	}

}