本文整理汇总了Golang中github.com/codegangsta/cli.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: getCommands
func getCommands(config Config) []cli.Command {
exportCmds := []cli.Command{}
var keys []string
for k := range config.Commands {
keys = append(keys, k)
}
sort.Strings(keys)
for _, name := range keys {
cmd := config.Commands[name]
cmdName := name
subCommands := []cli.Command{}
// Handle the import of subcommands.
if cmd.Import != "" {
// If the first character isn't "/" or "~" we assume a relative path.
subSource := cmd.Import
if cmd.Import[0] != "/"[0] || cmd.Import[0] != "~"[0] {
subSource = filepath.Join(sourcedir, cmd.Import)
}
logger("info", "Importing commands into '"+name+"' command from "+subSource)
subConfig, _ := getConfig(subSource)
subCommands = getCommands(subConfig)
}
newCmd := cli.Command{
Name: name,
SkipFlagParsing: true,
HideHelp: cmd.Hide,
}
if cmd.Usage != "" {
newCmd.Usage = cmd.Usage
}
if cmd.Cmd != "" {
newCmd.Action = func(c *cli.Context) {
args = c.Args()
runCommand(cmdName, cmd.Cmd)
}
}
if subCommands != nil {
newCmd.Subcommands = subCommands
}
//log.Println("found command: ", name, " > ", cmd.Cmd )
exportCmds = append(exportCmds, newCmd)
}
return exportCmds
}
开发者ID:dkinzer,项目名称:ahoy,代码行数:53,代码来源:ahoy.go
示例4: 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
}
开发者ID:rusnassonov,项目名称:yat,代码行数:57,代码来源:yandex_translator.go
示例5: selinuxCommand
func selinuxCommand() cli.Command {
app := cli.Command{}
app.Name = "selinux"
app.Usage = "Launch SELinux tools container."
app.Action = func(c *cli.Context) error {
argv := []string{"system-docker", "run", "-it", "--privileged", "--rm",
"--net", "host", "--pid", "host", "--ipc", "host",
"-v", "/usr/bin/docker:/usr/bin/docker.dist:ro",
"-v", "/usr/bin/ros:/usr/bin/dockerlaunch:ro",
"-v", "/usr/bin/ros:/usr/bin/user-docker:ro",
"-v", "/usr/bin/ros:/usr/bin/system-docker:ro",
"-v", "/usr/bin/ros:/sbin/poweroff:ro",
"-v", "/usr/bin/ros:/sbin/reboot:ro",
"-v", "/usr/bin/ros:/sbin/halt:ro",
"-v", "/usr/bin/ros:/sbin/shutdown:ro",
"-v", "/usr/bin/ros:/usr/bin/respawn:ro",
"-v", "/usr/bin/ros:/usr/bin/ros:ro",
"-v", "/usr/bin/ros:/usr/bin/cloud-init:ro",
"-v", "/usr/bin/ros:/usr/sbin/netconf:ro",
"-v", "/usr/bin/ros:/usr/sbin/wait-for-network:ro",
"-v", "/usr/bin/ros:/usr/sbin/wait-for-docker:ro",
"-v", "/var/lib/docker:/var/lib/docker",
"-v", "/var/lib/rkt:/var/lib/rkt",
"-v", "/dev:/host/dev",
"-v", "/etc/docker:/etc/docker",
"-v", "/etc/hosts:/etc/hosts",
"-v", "/etc/resolv.conf:/etc/resolv.conf",
"-v", "/etc/rkt:/etc/rkt",
"-v", "/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
"-v", "/lib/firmware:/lib/firmware",
"-v", "/lib/modules:/lib/modules",
"-v", "/run:/run",
"-v", "/usr/share/ros:/usr/share/ros",
"-v", "/var/lib/rancher/conf:/var/lib/rancher/conf",
"-v", "/var/lib/rancher:/var/lib/rancher",
"-v", "/var/log:/var/log",
"-v", "/var/run:/var/run",
"-v", "/home:/home",
"-v", "/opt:/opt",
"-v", "/etc/selinux:/etc/selinux",
"-v", "/var/lib/selinux:/var/lib/selinux",
"-v", "/usr/share/selinux:/usr/share/selinux",
fmt.Sprintf("rancher/os-selinuxtools:%s", config.VERSION+config.SUFFIX), "bash"}
syscall.Exec("/bin/system-docker", argv, []string{})
return nil
}
return app
}
开发者ID:xingdl2007,项目名称:os,代码行数:49,代码来源:selinux.go
示例6: Wrap
func (w *crashHandler) Wrap(cmd cli.Command) cli.Command {
oldAction := cmd.Action
cmd.Action = func(c *cli.Context) {
oldAction(c)
}
return cmd
}
开发者ID:postfix,项目名称:axiom,代码行数:7,代码来源:axiom.go
示例7: wrap_cmd
func wrap_cmd(cfg *watch.Config, c cli.Command) cli.Command {
a := c.Action.(func(*cli.Context))
c.Action = func(c *cli.Context) {
setup_action(cfg, c)
a(c)
}
return c
}
开发者ID:draxil,项目名称:springboard,代码行数:8,代码来源:springboard.go
示例8: 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
示例9: TestCommandDoNotIgnoreFlags
func TestCommandDoNotIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
set.Parse(test)
c := cli.NewContext(app, set, set)
command := cli.Command{
Name: "test-cmd",
ShortName: "tc",
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) {},
}
err := command.Run(c)
expect(t, err.Error(), "flag provided but not defined: -break")
}
开发者ID:carriercomm,项目名称:empire,代码行数:19,代码来源:command_test.go
示例10: MakeCLI
// MakeCLI creates the CLI tree for a Host info
func (h HostInfo) MakeCLI() []cli.Command {
sc := make([]cli.Command, 0, len(h.Types))
for _, key := range h.Types.List() {
cat := h.Types[key]
cc := cli.Command{ // cc = category command
Name: key,
Usage: cat.Summary,
HideHelp: true,
Subcommands: make([]cli.Command, 0, len(cat.Hosts)),
Action: func(c *cli.Context) {
cat.PrimaryHost().Execute("")
},
}
for _, host := range cat.Hosts {
hc := cli.Command{ // hc = host command
Name: host.FQDN,
Usage: host.Summary,
HideHelp: true,
Action: func(c *cli.Context) {
var host *Host
args := c.Args()
if len(args) == 0 {
// No extra arguments - go to the primary host
host = cat.PrimaryHost()
} else {
// Arguments were defined - go to the fqdn specified
// TODO(thiderman): Error handling, integer index handling
host = cat.GetHost(args[0])
}
host.Execute("")
},
}
cc.Subcommands = append(cc.Subcommands, hc)
}
sc = append(sc, cc)
}
return sc
}
开发者ID:thiderman,项目名称:sagacity,代码行数:43,代码来源:host.go
示例11: TestCommandIgnoreFlags
func TestCommandIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah"}
set.Parse(test)
c := cli.NewContext(app, set, set)
command := cli.Command{
Name: "test-cmd",
ShortName: "tc",
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) {},
SkipFlagParsing: true,
}
err := command.Run(c)
expect(t, err, nil)
}
开发者ID:carriercomm,项目名称:empire,代码行数:20,代码来源:command_test.go
示例12: getCommands
func getCommands(config Config) []cli.Command {
exportCmds := []cli.Command{}
var keys []string
for k := range config.Commands {
keys = append(keys, k)
}
sort.Strings(keys)
for _, name := range keys {
cmd := config.Commands[name]
cmdName := name
newCmd := cli.Command{
Name: name,
SkipFlagParsing: true,
HideHelp: cmd.Hide,
}
if cmd.Usage != "" {
newCmd.Usage = cmd.Usage
}
if cmd.Cmd != "" {
newCmd.Action = func(c *cli.Context) {
args = c.Args()
runCommand(cmdName, cmd.Cmd)
}
}
subCommands := getSubCommands(cmd.Imports)
if subCommands != nil {
newCmd.Subcommands = subCommands
}
//log.Println("found command: ", name, " > ", cmd.Cmd )
exportCmds = append(exportCmds, newCmd)
}
return exportCmds
}
开发者ID:DevinciHQ,项目名称:ahoy,代码行数:41,代码来源:ahoy.go
示例13: init
func init() {
cmd := &ExecCommand{}
flags := clihelpers.GetFlagsFromStruct(cmd)
cliCmd := cli.Command{
Name: "exec",
Usage: "execute a build locally",
}
for _, executor := range common.GetExecutors() {
subCmd := cli.Command{
Name: executor,
Usage: "use " + executor + " executor",
Action: cmd.Execute,
Flags: flags,
}
cliCmd.Subcommands = append(cliCmd.Subcommands, subCmd)
}
common.RegisterCommand(cliCmd)
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:21,代码来源:exec.go
示例14: init
func init() {
catalogCmd := cli.Command{
Name: "catalog",
Usage: "Manage Otsimo catalogs",
}
catalogCmd.Subcommands = []cli.Command{
{
Name: "push",
Usage: "push catalog",
Action: catalogPush,
},
{
Name: "validate",
Usage: "validate catalog file",
Action: catalogValidate,
},
{
Name: "current",
Usage: "get current accessible catalog",
Action: catalogCurrent,
},
{
Name: "approve",
Usage: "approve a catalog",
Action: catalogApprove,
},
{
Name: "list",
Usage: "list catalogs",
Action: catalogList,
Flags: []cli.Flag{
cli.BoolFlag{Name: "hide-expired"},
cli.IntFlag{Name: "limit", Value: 100},
cli.StringFlag{Name: "status", Value: "both", Usage: "catalog status: both, draft, approved"},
},
},
}
commands = append(commands, catalogCmd)
}
开发者ID:otsimo,项目名称:otsimoctl,代码行数:39,代码来源:catalog_cmd.go
示例15: getCommand
func getCommand(baseName string, metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command {
command := cli.Command{
Name: metadata.Name,
Aliases: metadata.Aliases,
ShortName: metadata.ShortName,
Description: metadata.Description,
Usage: strings.Replace(metadata.Usage, "BROOKLYN_NAME", baseName, -1),
Action: func(context *cli.Context) {
err := runner.RunCmdByName(metadata.Name, context)
if err != nil {
error_handler.ErrorExit(err)
}
},
Flags: metadata.Flags,
SkipFlagParsing: metadata.SkipFlagParsing,
}
if nil != metadata.Operands {
command.Subcommands = make([]cli.Command, 0)
for _, operand := range metadata.Operands {
command.Subcommands = append(command.Subcommands, cli.Command{
Name: operand.Name,
Aliases: operand.Aliases,
ShortName: operand.ShortName,
Description: operand.Description,
Usage: operand.Usage,
Flags: operand.Flags,
SkipFlagParsing: operand.SkipFlagParsing,
Action: subCommandAction(command.Name, operand.Name, runner),
})
command.Usage = strings.Join([]string{
command.Usage, "\n... ", operand.Usage, "\t", operand.Description,
}, "")
}
}
return command
}
开发者ID:ahgittin,项目名称:brooklyn-client,代码行数:38,代码来源:app.go
示例16: init
func init() {
gameCmd := cli.Command{
Name: "game",
Usage: "Manage games",
}
gameCmd.Subcommands = []cli.Command{{
Name: "init",
Action: gameInit,
Usage: "Creates a new empty game",
}, {
Name: "list",
Action: gameList,
Usage: "Shows list of games",
Flags: []cli.Flag{
cli.StringFlag{Name: "state", Value: "any", Usage: "available values are: any, created, dev, waiting, validated, production"},
cli.IntFlag{Name: "limit", Value: 100, Usage: "limit return results"},
},
}, {
Name: "publish",
Action: gamePublish,
Usage: "Upload the game at current directory",
}, {
Name: "change-state",
Action: gameChangeState,
Usage: "Changes a game's state",
Description: "ex: 'otsimoctl change-state sample-game 0.1.2 validated'",
}, {
Name: "info",
Action: gameEnv,
Usage: "Info of the game at current directory",
Flags: []cli.Flag{
cli.BoolFlag{Name: "env"},
},
}}
commands = append(commands, gameCmd)
}
开发者ID:otsimo,项目名称:otsimoctl,代码行数:38,代码来源:game.go
示例17: 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
}
开发者ID:rusnassonov,项目名称:yat,代码行数:37,代码来源:multitran_translator.go
示例18: MakeCLI
// MakeCLI generates a cli.Command chain based on the repository structure
func (r *Repo) MakeCLI() (c cli.Command) {
c = cli.Command{
Name: r.Key,
Usage: r.Summary,
HideHelp: true,
}
// Make a list of subcommands to add into the Command.
subcommands := make([]cli.Command, 0, len(r.Items)+len(r.Subrepos))
// Loop over the subrepositories first, making sure that they are on top.
for _, key := range r.SubrepoKeys() {
subrepo := r.Subrepos[key]
subcommands = append(subcommands, subrepo.MakeCLI())
}
// Then loop the item files.
for _, key := range r.Keys() {
item := r.Items[key]
sc := cli.Command{
Name: item.ID(),
Usage: item.Summary(),
HideHelp: true,
Action: item.Execute,
}
sc.Subcommands = append(sc.Subcommands, item.MakeCLI()...)
subcommands = append(subcommands, sc)
}
c.Subcommands = subcommands
return
}
开发者ID:thiderman,项目名称:sagacity,代码行数:37,代码来源:repo.go
示例19: 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
示例20: presentCmdName
func presentCmdName(cmd cli.Command) (name string) {
name = strings.Join(cmd.Names(), ", ")
return
}
开发者ID:davidwadden,项目名称:lattice-release,代码行数:4,代码来源:app_help.go
注:本文中的github.com/codegangsta/cli.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论