本文整理匯總了Golang中github.com/codegangsta/cli.Command.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.Args方法的具體用法?Golang Command.Args怎麽用?Golang Command.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/codegangsta/cli.Command
的用法示例。
在下文中一共展示了Command.Args方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetCli
func (yat *YandexTranslator) GetCli() *cli.Command {
c := cli.Command{
Name: "yandex",
Aliases: []string{"ya"},
Usage: "Yandex translator",
Flags: []cli.Flag{
cli.StringFlag{
Name: "api-key-file, f",
Value: ".yandex_api_key",
Usage: "yandex api key file",
EnvVar: "YANDEX_API_KEY_FILE",
},
},
Subcommands: []cli.Command{
{
Name: "translate",
Aliases: []string{"tr"},
Usage: "Translate with yandex translator",
Action: func(c *cli.Context) {
key, err := utilits.ReadFile(c.Parent().String("api-key-file"))
if err != nil {
fmt.Println(err)
return
}
yat.Key = key
langs := utilits.ParseLang(c.Args()[0])
tr, err := yat.Translate(c.Args()[1], langs[0], langs[1])
if err != nil {
fmt.Println(err)
return
}
fmt.Println(tr)
},
},
{
Name: "langs",
Usage: "Get supported languages",
Aliases: []string{"l"},
Action: func(c *cli.Context) {
key, err := utilits.ReadFile(c.Parent().String("api-key-file"))
if err != nil {
fmt.Println(err)
}
yat.Key = key
langs, err := yat.GetLangs()
if err != nil {
fmt.Println(err)
}
fmt.Println(langs)
},
},
},
}
return &c
}
示例2: GetCli
func (mt *MultitranTranslator) GetCli() *cli.Command {
c := cli.Command{
Name: "multitran",
Aliases: []string{"mt"},
Usage: "Multitran translator",
Subcommands: []cli.Command{
{
Name: "translate",
Aliases: []string{"tr"},
Usage: "Translate with multitran translator",
Action: func(c *cli.Context) {
langs := utilits.ParseLang(c.Args()[0])
tr, err := mt.Translate(c.Args()[1], langs[0], langs[1])
if err != nil {
fmt.Println(err)
return
}
fmt.Println(tr)
},
},
{
Name: "langs",
Usage: "Get supported languages",
Aliases: []string{"l"},
Action: func(c *cli.Context) {
langs, err := mt.GetLangs()
if err != nil {
fmt.Println(err)
}
fmt.Println(langs)
},
},
},
}
return &c
}