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