本文整理汇总了Golang中github.com/codegangsta/cli.Command.Aliases方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Aliases方法的具体用法?Golang Command.Aliases怎么用?Golang Command.Aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Command
的用法示例。
在下文中一共展示了Command.Aliases方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
app := cli.NewApp()
app.Name = "upx"
app.Usage = "a tool for managing files in UPYUN"
app.Author = "Hongbo.Mo"
app.Email = "[email protected]"
app.Version = fmt.Sprintf("%s %s/%s %s", version, runtime.GOOS,
runtime.GOARCH, runtime.Version())
app.Commands = make([]cli.Command, 0)
sort.Strings(cmds)
for _, cmd := range cmds {
cm, exist := CmdMap[cmd]
if exist {
Cmd := cli.Command{
Name: cmd,
Usage: cm.Desc,
Action: func(c *cli.Context) error {
if c.Command.FullName() != "login" && driver == nil {
fmt.Println("Log in first.")
os.Exit(-1)
}
opts := make(map[string]interface{})
for k, v := range cm.Flags {
if c.IsSet(k) {
switch v.typ {
case "bool":
opts[k] = c.Bool(k)
case "string":
opts[k] = c.String(k)
case "int":
opts[k] = c.Int(k)
}
}
}
cm.Func(c.Args(), opts)
return nil
},
}
if cm.Alias != "" {
Cmd.Aliases = []string{cm.Alias}
}
if cm.Flags != nil {
Cmd.Flags = []cli.Flag{}
for k, v := range cm.Flags {
var flag cli.Flag
switch v.typ {
case "bool":
flag = cli.BoolFlag{Name: k, Usage: v.usage}
case "int":
flag = cli.StringFlag{Name: k, Usage: v.usage}
case "string":
flag = cli.IntFlag{Name: k, Usage: v.usage}
}
Cmd.Flags = append(Cmd.Flags, flag)
}
}
app.Commands = append(app.Commands, Cmd)
}
}
app.Run(os.Args)
}