本文整理汇总了Golang中github.com/codegangsta/cli.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例6: Wrap
func (w *crashHandler) Wrap(cmd cli.Command) cli.Command {
oldAction := cmd.Action
cmd.Action = func(c *cli.Context) {
oldAction(c)
}
return cmd
}
示例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
}
示例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
}
示例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")
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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
}