本文整理汇总了Golang中github.com/codegangsta/cli.Command.Subcommands方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Subcommands方法的具体用法?Golang Command.Subcommands怎么用?Golang Command.Subcommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Command
的用法示例。
在下文中一共展示了Command.Subcommands方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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)
}
示例7: 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)
}
示例8: 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)
}
示例9: 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
}