本文整理汇总了Golang中github.com/codegangsta/cli.Command.Flags方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Flags方法的具体用法?Golang Command.Flags怎么用?Golang Command.Flags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Command
的用法示例。
在下文中一共展示了Command.Flags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serviceCommand
func serviceCommand() cli.Command {
factory := &projectFactory{}
app := cli.Command{}
app.Name = "service"
app.ShortName = "s"
app.Usage = "Command line interface for services and compose."
app.Before = beforeApp
app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
app.Subcommands = append(serviceSubCommands(),
command.BuildCommand(factory),
command.CreateCommand(factory),
command.UpCommand(factory),
command.StartCommand(factory),
command.LogsCommand(factory),
command.RestartCommand(factory),
command.StopCommand(factory),
command.ScaleCommand(factory),
command.RmCommand(factory),
command.PullCommand(factory),
command.KillCommand(factory),
command.PortCommand(factory),
command.PsCommand(factory),
)
return app
}
示例2: addDriverFlagsToCommand
func addDriverFlagsToCommand(cliFlags []cli.Flag, cmd *cli.Command) *cli.Command {
cmd.Flags = append(SharedCreateFlags, cliFlags...)
cmd.SkipFlagParsing = false
cmd.Action = runCommand(cmdCreateInner)
sort.Sort(ByFlagName(cmd.Flags))
return cmd
}
示例3: getRunCommand
func getRunCommand() cli.Command {
actionRun := func(c *cli.Context) {
cliApplicationAction(c)
if !c.IsSet("db-host") {
cli.ShowCommandHelp(c, "run")
return
}
goAuthApp := app.NewApplication(c.String("db-user"), c.String("db-password"),
c.String("database"), c.String("db-host"), c.Int("db-port"), c.Int("port"))
goAuthApp.Run()
}
cmdRun := cli.Command{
Name: "run",
Usage: "Run the authentication service",
Action: actionRun,
}
cmdRun.Flags = []cli.Flag{
cli.StringFlag{
Name: "db-host",
Usage: "The Database Hostname",
},
cli.IntFlag{
Name: "db-port",
Usage: "The Database port",
Value: 3306,
},
cli.StringFlag{
Name: "db-user",
Usage: "The Database Username",
Value: "messenger",
},
cli.StringFlag{
Name: "db-password",
Usage: "The Database Password",
Value: "messenger",
},
cli.StringFlag{
Name: "database",
Usage: "The Database name",
Value: "messenger",
},
cli.IntFlag{
Name: "port, p",
Usage: "The port on which this app will serve requests",
Value: 8080,
},
}
return cmdRun
}
示例4: Wrap
func (w *YAMLConfigLoader) Wrap(cmd cli.Command) cli.Command {
cmd.Flags = append(cmd.Flags, []cli.Flag{
cli.StringFlag{"config", w.DefaultPath, "path to YAML config file", ""},
}...)
oldAction := cmd.Action
cmd.Action = func(c *cli.Context) {
configFile := c.String("config")
if configFile != "" {
err := w.LoadFromFile(configFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
oldAction(c)
}
return cmd
}
示例5: 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)
}