コード例 #1
0
ファイル: helpers.go プロジェクト: mssola/zypper-docker
// It appends the set flags with the given command.
// `boolFlags` is a list of strings containing the names of the boolean
// command line options. These have to be handled in a slightly different
// way because zypper expects `--boolflag` instead of `--boolflag true`. Also
// boolean flags with a false value are ignored because zypper set all the
// undefined bool flags to false by default.
// `toIgnore` contains a list of flag names to not be passed to the final
//  command, this is useful to prevent zypper-docker only parameters to be
// forwarded to zypper (eg: `--author` or `--message`).
func cmdWithFlags(cmd string, ctx *cli.Context, boolFlags, toIgnore []string) string {
	for _, name := range ctx.FlagNames() {
		if arrayIncludeString(toIgnore, name) {
			continue
		}

		if value := ctx.String(name); ctx.IsSet(name) {
			var dash string
			if len(name) == 1 {
				dash = "-"
			} else {
				dash = "--"
			}

			if arrayIncludeString(boolFlags, name) {
				cmd += fmt.Sprintf(" %v%s", dash, name)
			} else {
				if arrayIncludeString(specialFlags, fmt.Sprintf("%v%s", dash, name)) && value != "" {
					cmd += fmt.Sprintf(" %v%s=%s", dash, name, value)
				} else {
					cmd += fmt.Sprintf(" %v%s %s", dash, name, value)
				}
			}
		}
	}

	return cmd
}
コード例 #2
0
ファイル: cmd_helper.go プロジェクト: odacremolbap/concerto
func debugCmdFuncInfo(c *cli.Context) {
	if log.GetLevel() < log.DebugLevel {
		return
	}

	// get function name
	dbgMsg := ""
	pc, _, _, ok := runtime.Caller(1)
	if ok {
		dbgMsg = runtime.FuncForPC(pc).Name()
		i := strings.LastIndex(dbgMsg, "/")
		if i != -1 {
			dbgMsg = dbgMsg[i+1:]
		}
	} else {
		dbgMsg = "<unknown function name>"
	}
	dbgMsg = fmt.Sprintf("func %s", dbgMsg)

	// get used flags
	for _, flag := range c.FlagNames() {
		dbgMsg = fmt.Sprintf("%s\n\t%s=%+v", dbgMsg, flag, c.Generic(flag))
	}
	log.Debugf(dbgMsg)
}
コード例 #3
0
ファイル: cmd_helper.go プロジェクト: odacremolbap/concerto
// flagConvertParams converts cli parameters in API callable params
func flagConvertParams(c *cli.Context) *map[string]string {
	v := make(map[string]string)
	for _, flag := range c.FlagNames() {
		if c.IsSet(flag) {
			v[flag] = c.String(flag)
		}
	}
	return &v
}
コード例 #4
0
// parse a codegansta/cli context and return a slice of flag=value.
func flagsFromContext(c *cli.Context) []string {
	flags := []string{}

	for _, flag := range c.FlagNames() {
		// Only add the flag and value if the value is not a zero value.
		if value := c.String(flag); !isStringZeroValue(value) {
			flags = append(flags, fmt.Sprintf(`--%s="%s"`, flag, value))
		}
	}

	return flags
}
コード例 #5
0
// isEmpty method check is the given argument is empty or not. Parameter with empty values are not allowed in opsgenie-lamp
func isEmpty(argName string, arg string, c *gcli.Context) bool {
	var prefix string
	for _, name := range c.FlagNames() {
		if len(name) == 1 {
			prefix = "-"
		} else {
			prefix = "--"
		}
		if strings.Contains(arg, prefix+name) {
			fmt.Printf("Value of argument '%s' is empty\n", argName)
			gcli.ShowCommandHelp(c, c.Command.Name)
			os.Exit(1)
		}
	}
	return false
}
コード例 #6
0
ファイル: entity.go プロジェクト: ahgittin/brooklyn-client
func (cmd *Entity) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	if c.NumFlags() > 0 && c.FlagNames()[0] == "children" {
		cmd.listentity(scope.Application, c.StringSlice("children")[0])
	} else {
		if c.Args().Present() {
			cmd.show(scope.Application, c.Args().First())
		} else {
			if scope.Entity == scope.Application {
				cmd.listapp(scope.Application)
			} else {
				cmd.listentity(scope.Application, scope.Entity)
			}
		}
	}
}
コード例 #7
0
ファイル: validate.go プロジェクト: podtools/pod
func processFlags(c *cli.Context) {
	for f := range c.FlagNames() {
		switch c.FlagNames()[f] {
		case "create":
			create = true
		case "file":
			fileLocation = c.String(c.FlagNames()[f])
		case "profile":
			profile = c.String(c.FlagNames()[f])
		}
	}
}