當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Command.Flags方法代碼示例

本文整理匯總了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
}
開發者ID:carriercomm,項目名稱:os,代碼行數:27,代碼來源:service.go

示例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
}
開發者ID:RaulKite,項目名稱:machine,代碼行數:8,代碼來源:create.go

示例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
}
開發者ID:kwangyoung,項目名稱:go-messenger,代碼行數:56,代碼來源:main.go

示例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
}
開發者ID:postfix,項目名稱:axiom,代碼行數:18,代碼來源:axiom.go

示例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)
}
開發者ID:GeorgeChan,項目名稱:upx,代碼行數:64,代碼來源:upx.go


注:本文中的github.com/codegangsta/cli.Command.Flags方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。