本文整理汇总了Golang中github.com/codegangsta/cli.Command.Action方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Action方法的具体用法?Golang Command.Action怎么用?Golang Command.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Command
的用法示例。
在下文中一共展示了Command.Action方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Wrap
func (w *crashHandler) Wrap(cmd cli.Command) cli.Command {
oldAction := cmd.Action
cmd.Action = func(c *cli.Context) {
oldAction(c)
}
return cmd
}
示例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
}
示例3: 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
}
示例4: 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
}
示例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: 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
}
示例7: testTileAction
func testTileAction(actionName string) {
var (
controlErrorHandler = new(ErrorHandler)
)
Context(fmt.Sprintf("when called with the %s command name", actionName), func() {
controlName := actionName
controlUsage := "something about the usage here"
It("Then it should return a cli.Command with required values", func() {
cmd := CreateBURACliCommand(controlName, controlUsage, controlErrorHandler)
Ω(cmd.Name).Should(Equal(controlName))
Ω(cmd.Usage).Should(Equal(controlUsage))
Ω(cmd.Action).ShouldNot(BeNil())
})
Describe(fmt.Sprintf("given a %s command with an Action value", actionName), func() {
var (
controlExit = 0
controlCliContext *cli.Context
controlCmd cli.Command
)
BeforeEach(func() {
controlErrorHandler = new(ErrorHandler)
controlErrorHandler.ExitCode = controlExit
})
Context("when the action is called with all proper flags on a registered tile", func() {
var (
controlTileName = "fake-tile"
controlTileGenerator *fake.TileGenerator
controlTile *fake.Tile
)
BeforeEach(func() {
controlTile = new(fake.Tile)
controlTileGenerator = new(fake.TileGenerator)
controlTileGenerator.TileSpy = controlTile
tileregistry.Register(controlTileName, controlTileGenerator)
set := flag.NewFlagSet("", 0)
set.String("tile", controlTileName, "")
set.String("opsmanagerhost", "*****", "")
set.String("adminuser", "*****", "")
set.String("adminpass", "*****", "")
set.String("opsmanageruser", "*****", "")
set.String("opsmanagerpass", "*****", "")
set.String("destination", "*****", "")
controlCliContext = cli.NewContext(cli.NewApp(), set, nil)
controlCmd = CreateBURACliCommand(controlName, controlUsage, controlErrorHandler)
controlCliContext.Command = controlCmd
})
It("then it should execute a call on the tiles Action func()", func() {
controlCmd.Action(controlCliContext)
Ω(controlErrorHandler.ExitCode).Should(Equal(controlExit))
Ω(controlErrorHandler.Error).ShouldNot(HaveOccurred())
switch controlName {
case "backup":
Ω(controlTile.BackupCallCount).ShouldNot(Equal(0))
case "restore":
Ω(controlTile.RestoreCallCount).ShouldNot(Equal(0))
default:
panic("this should never happen")
}
})
})
Context("when the action is called w/o a matching registered tile", func() {
BeforeEach(func() {
set := flag.NewFlagSet(controlName, 0)
set.Bool("myflag", false, "doc")
set.String("otherflag", "hello world", "doc")
controlCliContext = cli.NewContext(cli.NewApp(), set, nil)
controlCmd = CreateBURACliCommand(controlName, controlUsage, controlErrorHandler)
controlCliContext.Command = controlCmd
})
It("then it should set an error and failure exit code", func() {
controlCmd.Action(controlCliContext)
Ω(controlErrorHandler.ExitCode).ShouldNot(Equal(controlExit))
Ω(controlErrorHandler.Error).Should(HaveOccurred())
Ω(controlErrorHandler.Error).Should(Equal(ErrInvalidTileSelection))
})
})
Context("when the action is called w/o proper flags but with a registered tile", func() {
var controlTileName = "fake-tile"
BeforeEach(func() {
tileregistry.Register(controlTileName, new(fake.TileGenerator))
set := flag.NewFlagSet("", 0)
set.String("tile", controlTileName, "doc")
set.Bool("myflag", false, "doc")
set.String("otherflag", "hello world", "doc")
controlCliContext = cli.NewContext(cli.NewApp(), set, nil)
controlCmd = CreateBURACliCommand(controlName, controlUsage, controlErrorHandler)
controlCliContext.Command = controlCmd
})
It("then it should set an error and failure exit code", func() {
controlCmd.Action(controlCliContext)
Ω(controlErrorHandler.ExitCode).ShouldNot(Equal(controlExit))
Ω(controlErrorHandler.Error).Should(HaveOccurred())
Ω(controlErrorHandler.Error).Should(Equal(ErrInvalidFlagArgs))
//.........这里部分代码省略.........