本文整理汇总了Golang中github.com/codegangsta/cli.Context.Generic方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Generic方法的具体用法?Golang Context.Generic怎么用?Golang Context.Generic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Generic方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: ValidateMultiArgs
func ValidateMultiArgs(c *cli.Context) bool {
if c.Generic("muser") == nil {
return false
}
if c.Generic("mpassword") == nil {
return false
}
return true
}
示例3: cmdServiceAdd
// serviced service add [[-p PORT]...] [[-q REMOTE]...] [--parent-id SERVICEID] NAME IMAGEID COMMAND
func (c *ServicedCli) cmdServiceAdd(ctx *cli.Context) {
args := ctx.Args()
if len(args) < 3 {
fmt.Printf("Incorrect Usage.\n\n")
cli.ShowCommandHelp(ctx, "add")
return
}
var (
parentService *service.Service
err error
)
if parentServiceID := ctx.String("parent-id"); parentServiceID == "" {
fmt.Fprintln(os.Stderr, "Must specify a parent service ID")
return
} else if parentService, err = c.searchForService(parentServiceID); err != nil {
fmt.Fprintf(os.Stderr, "Error searching for parent service: %s", err)
return
}
cfg := api.ServiceConfig{
Name: args[0],
ImageID: args[1],
Command: args[2],
ParentServiceID: parentService.ID,
LocalPorts: ctx.Generic("p").(*api.PortMap),
RemotePorts: ctx.Generic("q").(*api.PortMap),
}
if service, err := c.driver.AddService(cfg); err != nil {
fmt.Fprintln(os.Stderr, err)
} else if service == nil {
fmt.Fprintln(os.Stderr, "received nil service definition")
} else {
fmt.Println(service.ID)
}
}
示例4: buildConvoyCmdArgs
func buildConvoyCmdArgs(c *cli.Context, socket string) []string {
convoyCmd := []string{fmt.Sprintf(flagFmt, "socket", socket), "daemon"}
for flagName, flagType := range convoyFlags {
if !c.IsSet(flagName) {
continue
}
f := c.Generic(flagName)
flagName = flagName[len(convoyFlagNamePrefix):]
logrus.Infof("Got: %s %v", flagName, f)
switch flagType {
case "string":
fallthrough
case "bool":
fl := f.(flag.Getter)
convoyCmd = append(convoyCmd, fmt.Sprintf(flagFmt, flagName, fl.String()))
case "stringslice":
fl := f.(*cli.StringSlice)
for _, val := range fl.Value() {
convoyCmd = append(convoyCmd, fmt.Sprintf(flagFmt, flagName, val))
}
}
}
return convoyCmd
}
示例5: ValidateExtraArgs
func ValidateExtraArgs(c *cli.Context) bool {
if c.Generic("legacy-dsn") == nil {
return false
}
if c.Generic("legacy-user") == nil {
return false
}
if c.Generic("legacy-password") == nil {
return false
}
return true
}
示例6: ValidateArgs
func ValidateArgs(c *cli.Context) bool {
if c.Generic("dsn") == nil {
return false
}
if c.Generic("user") == nil {
return false
}
if c.Generic("password") == nil {
return false
}
return true
}