本文整理汇总了Golang中github.com/codegangsta/cli.Context.FlagNames方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FlagNames方法的具体用法?Golang Context.FlagNames怎么用?Golang Context.FlagNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.FlagNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdWithFlags
// 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: debugCmdFuncInfo
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: flagConvertParams
// 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: isEmpty
// 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
}
示例5: Run
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)
}
}
}
}
示例6: processFlags
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])
}
}
}