本文整理汇总了Golang中github.com/codegangsta/cli.App.Command方法的典型用法代码示例。如果您正苦于以下问题:Golang App.Command方法的具体用法?Golang App.Command怎么用?Golang App.Command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.App
的用法示例。
在下文中一共展示了App.Command方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newCmdPresenter
func newCmdPresenter(app *cli.App, maxNameLen int, cmdName string) (presenter cmdPresenter) {
cmd := app.Command(cmdName)
presenter.Name = presentCmdName(*cmd)
padding := strings.Repeat(" ", maxNameLen-len(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.Description
return
}
示例2: GetByCmdName
func GetByCmdName(app *cli.App, cmdName string) (cmd *cli.Command, err error) {
cmd = app.Command(cmdName)
if cmd == nil {
for _, c := range app.Commands {
if c.ShortName == cmdName {
return &c, nil
}
}
err = errors.New("Command not found")
}
return
}
示例3: newAppPresenter
func newAppPresenter(app *cli.App) (presenter appPresenter) {
maxNameLen := 0
for _, cmd := range app.Commands {
name := presentCmdName(cmd)
if utf8.RuneCountInString(name) > maxNameLen {
maxNameLen = len(name)
}
}
presentCommand := func(commandName string) (presenter cmdPresenter) {
cmd := app.Command(commandName)
presenter.Name = presentCmdName(*cmd)
padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.Description
return
}
presentNonCodegangstaCommand := func(commandName string) (presenter cmdPresenter) {
cmd := command_registry.Commands.FindCommand(commandName)
presenter.Name = cmd.MetaData().Name
padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.MetaData().Description
return
}
presentPluginCommands := func() []cmdPresenter {
pluginConfig := plugin_config.NewPluginConfig(func(err error) {
//fail silently when running help?
})
plugins := pluginConfig.Plugins()
var presenters []cmdPresenter
var pluginPresenter cmdPresenter
for _, pluginMetadata := range plugins {
for _, cmd := range pluginMetadata.Commands {
if cmd.Alias == "" {
pluginPresenter.Name = cmd.Name
} else {
pluginPresenter.Name = cmd.Name + ", " + cmd.Alias
}
padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(pluginPresenter.Name))
pluginPresenter.Name = pluginPresenter.Name + padding
pluginPresenter.Description = cmd.HelpText
presenters = append(presenters, pluginPresenter)
}
}
return presenters
}
presenter.Name = app.Name
presenter.Flags = app.Flags
presenter.Usage = app.Usage
presenter.Version = app.Version
presenter.Compiled = app.Compiled
presenter.Commands = []groupedCommands{
{
Name: T("GETTING STARTED"),
CommandSubGroups: [][]cmdPresenter{
{
presentNonCodegangstaCommand("login"),
presentNonCodegangstaCommand("logout"),
presentNonCodegangstaCommand("passwd"),
presentNonCodegangstaCommand("target"),
}, {
presentNonCodegangstaCommand("api"),
presentNonCodegangstaCommand("auth"),
},
},
}, {
Name: T("APPS"),
CommandSubGroups: [][]cmdPresenter{
{
presentNonCodegangstaCommand("apps"),
presentNonCodegangstaCommand("app"),
}, {
presentCommand("push"), //needs start/restart ...
presentCommand("scale"), //needs stop/restart
presentNonCodegangstaCommand("delete"),
presentNonCodegangstaCommand("rename"),
}, {
presentCommand("start"),
presentCommand("stop"),
presentCommand("restart"), //needs start
presentCommand("restage"),
presentCommand("restart-app-instance"),
}, {
presentNonCodegangstaCommand("events"),
presentNonCodegangstaCommand("files"),
presentNonCodegangstaCommand("logs"),
}, {
presentNonCodegangstaCommand("env"),
presentNonCodegangstaCommand("set-env"),
presentNonCodegangstaCommand("unset-env"),
}, {
presentNonCodegangstaCommand("stacks"),
//.........这里部分代码省略.........
示例4: newAppPresenter
func newAppPresenter(app *cli.App) (presenter appPresenter) {
maxNameLen := 0
for _, cmd := range app.Commands {
name := presentCmdName(cmd)
if utf8.RuneCountInString(name) > maxNameLen {
maxNameLen = len(name)
}
}
presentCommand := func(commandName string) (presenter cmdPresenter) {
cmd := app.Command(commandName)
presenter.Name = presentCmdName(*cmd)
padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.Usage
return
}
presenter.Name = app.Name
presenter.Flags = app.Flags
presenter.Usage = app.Usage
presenter.Version = app.Version
presenter.Authors = app.Authors
presenter.Commands = []groupedCommands{
{
Name: "TARGET LATTICE",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("target"),
},
},
}, {
Name: "MANAGE DOCKER APPS",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("create"),
},
},
}, {
Name: "MANAGE DROPLETS",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("build-droplet"),
presentCommand("export-droplet"),
presentCommand("import-droplet"),
presentCommand("launch-droplet"),
presentCommand("list-droplets"),
presentCommand("remove-droplet"),
},
},
}, {
Name: "MANAGE ALL APPS",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("remove"),
presentCommand("scale"),
presentCommand("update-routes"),
presentCommand("update"),
},
},
}, {
Name: "TASKS",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("cancel-task"),
presentCommand("delete-task"),
presentCommand("task"),
},
},
}, {
Name: "STREAM LOGS",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("logs"),
},
},
}, {
Name: "SEE WHATS RUNNING",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("cells"),
presentCommand("list"),
presentCommand("status"),
presentCommand("visualize"),
},
},
}, {
Name: "SSH INTO AN APP CONTAINER",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("ssh"),
},
},
}, {
Name: "ADVANCED",
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("submit-lrp"),
//.........这里部分代码省略.........
示例5: newAppPresenter
func newAppPresenter(app *cli.App) (presenter appPresenter) {
maxNameLen := 0
for _, cmd := range app.Commands {
name := presentCmdName(cmd)
if utf8.RuneCountInString(name) > maxNameLen {
maxNameLen = len(name)
}
}
presentCommand := func(commandName string) (presenter cmdPresenter) {
cmd := app.Command(commandName)
presenter.Name = presentCmdName(*cmd)
padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.Description
return
}
presenter.Name = app.Name
presenter.Flags = app.Flags
presenter.Usage = app.Usage
presenter.Version = app.Version
presenter.Compiled = app.Compiled
presenter.Commands = []groupedCommands{
{
Name: T("GETTING STARTED"),
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("login"),
presentCommand("logout"),
presentCommand("passwd"),
presentCommand("target"),
}, {
presentCommand("api"),
presentCommand("auth"),
},
},
}, {
Name: T("APPS"),
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("apps"),
presentCommand("app"),
}, {
presentCommand("push"),
presentCommand("scale"),
presentCommand("delete"),
presentCommand("rename"),
}, {
presentCommand("start"),
presentCommand("stop"),
presentCommand("restart"),
presentCommand("restage"),
}, {
presentCommand("events"),
presentCommand("files"),
presentCommand("logs"),
}, {
presentCommand("env"),
presentCommand("set-env"),
presentCommand("unset-env"),
}, {
presentCommand("stacks"),
},
},
}, {
Name: T("SERVICES"),
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("marketplace"),
presentCommand("services"),
presentCommand("service"),
}, {
presentCommand("create-service"),
presentCommand("delete-service"),
presentCommand("rename-service"),
}, {
presentCommand("bind-service"),
presentCommand("unbind-service"),
}, {
presentCommand("create-user-provided-service"),
presentCommand("update-user-provided-service"),
},
},
}, {
Name: T("ORGS"),
CommandSubGroups: [][]cmdPresenter{
{
presentCommand("orgs"),
presentCommand("org"),
}, {
presentCommand("create-org"),
presentCommand("delete-org"),
presentCommand("rename-org"),
},
},
}, {
Name: T("SPACES"),
CommandSubGroups: [][]cmdPresenter{
{
//.........这里部分代码省略.........
示例6:
})
It("returns if multiple bad flags are passed", func() {
cliAppArgs := []string{"ltc", "create", "--badflag1", "--badflag2"}
flags := main.GetCommandFlags(cliApp, cliAppArgs[1])
badFlags := main.MatchArgAndFlags(flags, cliAppArgs[2:])
main.InjectHelpTemplate(badFlags)
Expect(badFlags).To(Equal("Unknown flags: \"--badflag1\", \"--badflag2\""))
})
})
Describe("GetCommandFlags", func() {
It("returns flags string slice for a given command list of type Flag", func() {
flagList := main.GetCommandFlags(cliApp, "create")
cmd := cliApp.Command("create")
for _, flag := range cmd.Flags {
switch t := flag.(type) {
default:
Fail("unhandled flag type")
case cli.StringSliceFlag:
Expect(flagList).Should(ContainElement(t.Name))
case cli.IntFlag:
Expect(flagList).Should(ContainElement(t.Name))
case cli.StringFlag:
Expect(flagList).Should(ContainElement(t.Name))
case cli.BoolFlag:
Expect(flagList).Should(ContainElement(t.Name))
case cli.DurationFlag:
Expect(flagList).Should(ContainElement(t.Name))
}