本文整理汇总了Golang中github.com/juju/juju/cmd.NewSuperCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSuperCommand函数的具体用法?Golang NewSuperCommand怎么用?Golang NewSuperCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSuperCommand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDispatch
func (s *SuperCommandSuite) TestDispatch(c *gc.C) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
info := jc.Info()
c.Assert(info.Name, gc.Equals, "jujutest")
c.Assert(info.Args, gc.Equals, "<command> ...")
c.Assert(info.Doc, gc.Matches, helpCommandsText)
jc, _, err := initDefenestrate([]string{"discombobulate"})
c.Assert(err, gc.ErrorMatches, "unrecognized command: jujutest discombobulate")
info = jc.Info()
c.Assert(info.Name, gc.Equals, "jujutest")
c.Assert(info.Args, gc.Equals, "<command> ...")
c.Assert(info.Doc, gc.Matches, "commands:\n defenestrate - defenestrate the juju"+helpText)
jc, tc, err := initDefenestrate([]string{"defenestrate"})
c.Assert(err, gc.IsNil)
c.Assert(tc.Option, gc.Equals, "")
info = jc.Info()
c.Assert(info.Name, gc.Equals, "jujutest defenestrate")
c.Assert(info.Args, gc.Equals, "<something>")
c.Assert(info.Doc, gc.Equals, "defenestrate-doc")
_, tc, err = initDefenestrate([]string{"defenestrate", "--option", "firmly"})
c.Assert(err, gc.IsNil)
c.Assert(tc.Option, gc.Equals, "firmly")
_, tc, err = initDefenestrate([]string{"defenestrate", "gibberish"})
c.Assert(err, gc.ErrorMatches, `unrecognized args: \["gibberish"\]`)
// --description must be used on it's own.
_, _, err = initDefenestrate([]string{"--description", "defenestrate"})
c.Assert(err, gc.ErrorMatches, `unrecognized args: \["defenestrate"\]`)
}
示例2: TestRegister
func (s *SuperCommandSuite) TestRegister(c *gc.C) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
jc.Register(&TestCommand{Name: "flip"})
jc.Register(&TestCommand{Name: "flap"})
badCall := func() { jc.Register(&TestCommand{Name: "flap"}) }
c.Assert(badCall, gc.PanicMatches, "command already registered: flap")
}
示例3: NewSuperWithCallback
func NewSuperWithCallback(callback func(*cmd.Context, string, []string) error) cmd.Command {
return cmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujutest",
Log: &cmd.Log{},
MissingCallback: callback,
})
}
示例4: NewJujuCommand
func NewJujuCommand(ctx *cmd.Context) cmd.Command {
jcmd := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "juju",
Doc: jujuDoc,
MissingCallback: RunPlugin,
UserAliasesFilename: osenv.JujuXDGDataHomePath("aliases"),
})
jcmd.AddHelpTopic("basics", "Basic commands", helptopics.Basics)
jcmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider",
helptopics.OpenstackProvider, "openstack")
jcmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider",
helptopics.EC2Provider, "ec2", "aws", "amazon")
jcmd.AddHelpTopic("hpcloud-provider", "How to configure an HP Cloud provider",
helptopics.HPCloud, "hpcloud", "hp-cloud")
jcmd.AddHelpTopic("azure-provider", "How to configure a Windows Azure provider",
helptopics.AzureProvider, "azure")
jcmd.AddHelpTopic("maas-provider", "How to configure a MAAS provider",
helptopics.MAASProvider, "maas")
jcmd.AddHelpTopic("constraints", "How to use commands with constraints", helptopics.Constraints)
jcmd.AddHelpTopic("placement", "How to use placement directives", helptopics.Placement)
jcmd.AddHelpTopic("spaces", "How to configure more complex networks using spaces", helptopics.Spaces, "networking")
jcmd.AddHelpTopic("glossary", "Glossary of terms", helptopics.Glossary)
jcmd.AddHelpTopic("logging", "How Juju handles logging", helptopics.Logging)
jcmd.AddHelpTopic("juju", "What is Juju?", helptopics.Juju)
jcmd.AddHelpTopic("controllers", "About Juju Controllers", helptopics.JujuControllers)
jcmd.AddHelpTopic("users", "About users in Juju", helptopics.Users)
jcmd.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic)
registerCommands(jcmd, ctx)
return jcmd
}
示例5: jujuDMain
// Main registers subcommands for the jujud executable, and hands over control
// to the cmd package.
func jujuDMain(args []string, ctx *cmd.Context) (code int, err error) {
// Assuming an average of 200 bytes per log message, use up to
// 200MB for the log buffer.
defer logger.Debugf("jujud complete, code %d, err %v", code, err)
logCh, err := logsender.InstallBufferedLogWriter(1048576)
if err != nil {
return 1, errors.Trace(err)
}
jujud := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujud",
Doc: jujudDoc,
})
jujud.Log.NewWriter = func(target io.Writer) loggo.Writer {
return &jujudWriter{target: target}
}
jujud.Register(NewBootstrapCommand())
// TODO(katco-): AgentConf type is doing too much. The
// MachineAgent type has called out the separate concerns; the
// AgentConf should be split up to follow suit.
agentConf := agentcmd.NewAgentConf("")
machineAgentFactory := agentcmd.MachineAgentFactoryFn(agentConf, logCh, "")
jujud.Register(agentcmd.NewMachineAgentCmd(ctx, machineAgentFactory, agentConf, agentConf))
jujud.Register(agentcmd.NewUnitAgent(ctx, logCh))
jujud.Register(NewUpgradeMongoCommand())
code = cmd.Main(jujud, ctx, args[1:])
return code, nil
}
示例6: NewJujuCommand
func NewJujuCommand(ctx *cmd.Context) cmd.Command {
jcmd := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "juju",
Doc: jujuDoc,
MissingCallback: RunPlugin,
})
jcmd.AddHelpTopic("basics", "Basic commands", helpBasics)
jcmd.AddHelpTopic("local-provider", "How to configure a local (LXC) provider",
helpProviderStart+helpLocalProvider+helpProviderEnd)
jcmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider",
helpProviderStart+helpOpenstackProvider+helpProviderEnd, "openstack")
jcmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider",
helpProviderStart+helpEC2Provider+helpProviderEnd, "ec2", "aws", "amazon")
jcmd.AddHelpTopic("hpcloud-provider", "How to configure an HP Cloud provider",
helpProviderStart+helpHPCloud+helpProviderEnd, "hpcloud", "hp-cloud")
jcmd.AddHelpTopic("azure-provider", "How to configure a Windows Azure provider",
helpProviderStart+helpAzureProvider+helpProviderEnd, "azure")
jcmd.AddHelpTopic("maas-provider", "How to configure a MAAS provider",
helpProviderStart+helpMAASProvider+helpProviderEnd, "maas")
jcmd.AddHelpTopic("constraints", "How to use commands with constraints", helpConstraints)
jcmd.AddHelpTopic("placement", "How to use placement directives", helpPlacement)
jcmd.AddHelpTopic("glossary", "Glossary of terms", helpGlossary)
jcmd.AddHelpTopic("logging", "How Juju handles logging", helpLogging)
jcmd.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic)
registerCommands(jcmd, ctx)
return jcmd
}
示例7: jujuDMain
// Main registers subcommands for the jujud executable, and hands over control
// to the cmd package.
func jujuDMain(args []string, ctx *cmd.Context) (code int, err error) {
// Assuming an average of 200 bytes per log message, use up to
// 200MB for the log buffer.
logCh, err := logsender.InstallBufferedLogWriter(1048576)
if err != nil {
return 1, errors.Trace(err)
}
jujud := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujud",
Doc: jujudDoc,
})
jujud.Log.Factory = &writerFactory{}
jujud.Register(NewBootstrapCommand())
// TODO(katco-): AgentConf type is doing too much. The
// MachineAgent type has called out the separate concerns; the
// AgentConf should be split up to follow suit.
agentConf := agentcmd.NewAgentConf("")
machineAgentFactory := agentcmd.MachineAgentFactoryFn(
agentConf, logCh, looputil.NewLoopDeviceManager(),
)
jujud.Register(agentcmd.NewMachineAgentCmd(ctx, machineAgentFactory, agentConf, agentConf))
jujud.Register(agentcmd.NewUnitAgent(ctx, logCh))
code = cmd.Main(jujud, ctx, args[1:])
return code, nil
}
示例8: TestInfo
func (s *SuperCommandSuite) TestInfo(c *gc.C) {
commandsDoc := `commands:
flapbabble - flapbabble the juju
flip - flip the juju`
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujutest",
Purpose: "to be purposeful",
Doc: "doc\nblah\ndoc",
})
info := jc.Info()
c.Assert(info.Name, gc.Equals, "jujutest")
c.Assert(info.Purpose, gc.Equals, "to be purposeful")
// info doc starts with the jc.Doc and ends with the help command
c.Assert(info.Doc, gc.Matches, jc.Doc+"(.|\n)*")
c.Assert(info.Doc, gc.Matches, "(.|\n)*"+helpCommandsText)
jc.Register(&TestCommand{Name: "flip"})
jc.Register(&TestCommand{Name: "flapbabble"})
info = jc.Info()
c.Assert(info.Doc, gc.Matches, jc.Doc+"\n\n"+commandsDoc+helpText)
jc.Doc = ""
info = jc.Info()
c.Assert(info.Doc, gc.Matches, commandsDoc+helpText)
}
示例9: NewJujuCommand
func NewJujuCommand(ctx *cmd.Context) cmd.Command {
jcmd := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "juju",
Doc: jujuDoc,
MissingCallback: RunPlugin,
})
jcmd.AddHelpTopic("basics", "Basic commands", helptopics.Basics)
jcmd.AddHelpTopic("local-provider", "How to configure a local (LXC) provider",
helptopics.LocalProvider)
jcmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider",
helptopics.OpenstackProvider, "openstack")
jcmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider",
helptopics.EC2Provider, "ec2", "aws", "amazon")
jcmd.AddHelpTopic("hpcloud-provider", "How to configure an HP Cloud provider",
helptopics.HPCloud, "hpcloud", "hp-cloud")
jcmd.AddHelpTopic("azure-provider", "How to configure a Windows Azure provider",
helptopics.AzureProvider, "azure")
jcmd.AddHelpTopic("maas-provider", "How to configure a MAAS provider",
helptopics.MAASProvider, "maas")
jcmd.AddHelpTopic("constraints", "How to use commands with constraints", helptopics.Constraints)
jcmd.AddHelpTopic("placement", "How to use placement directives", helptopics.Placement)
jcmd.AddHelpTopic("glossary", "Glossary of terms", helptopics.Glossary)
jcmd.AddHelpTopic("logging", "How Juju handles logging", helptopics.Logging)
jcmd.AddHelpTopic("juju", "What is Juju?", helptopics.Juju)
jcmd.AddHelpTopic("juju-systems", "About Juju Environment Systems (JES)", helptopics.JujuSystems)
jcmd.AddHelpTopic("users", "About users in Juju", helptopics.Users)
jcmd.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic)
registerCommands(jcmd, ctx)
return jcmd
}
示例10: TestDescription
func (s *SuperCommandSuite) TestDescription(c *gc.C) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest", Purpose: "blow up the death star"})
jc.Register(&TestCommand{Name: "blah"})
ctx := testing.Context(c)
code := cmd.Main(jc, ctx, []string{"blah", "--description"})
c.Assert(code, gc.Equals, 0)
c.Assert(bufferString(ctx.Stdout), gc.Equals, "blow up the death star\n")
}
示例11: TestHelpWithPrefix
func (s *SuperCommandSuite) TestHelpWithPrefix(c *gc.C) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest", UsagePrefix: "juju"})
jc.Register(&TestCommand{Name: "blah"})
ctx := testing.Context(c)
code := cmd.Main(jc, ctx, []string{"blah", "--help"})
c.Assert(code, gc.Equals, 0)
stripped := strings.Replace(bufferString(ctx.Stdout), "\n", "", -1)
c.Assert(stripped, gc.Matches, ".*usage: juju jujutest blah.*blah-doc.*")
}
示例12: jujuLocalPlugin
func jujuLocalPlugin() cmd.Command {
plugin := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "juju local",
UsagePrefix: "juju",
Doc: localDoc,
Purpose: "local provider specific commands",
})
return plugin
}
示例13: TestRegisterAlias
func (s *SuperCommandSuite) TestRegisterAlias(c *gc.C) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
jc.Register(&TestCommand{Name: "flip", Aliases: []string{"flap", "flop"}})
info := jc.Info()
c.Assert(info.Doc, gc.Equals, `commands:
flap - alias for flip
flip - flip the juju
flop - alias for flip
help - show help on a command or other topic`)
}
示例14: NewJujuCommand
// NewJujuCommand ...
func NewJujuCommand(ctx *cmd.Context) cmd.Command {
jcmd := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "juju",
Doc: jujuDoc,
MissingCallback: RunPlugin,
UserAliasesFilename: osenv.JujuXDGDataHomePath("aliases"),
})
jcmd.AddHelpTopic("basics", "Basic Help Summary", usageHelp)
registerCommands(jcmd, ctx)
return jcmd
}
示例15: jujuDMain
// Main registers subcommands for the jujud executable, and hands over control
// to the cmd package.
func jujuDMain(args []string, ctx *cmd.Context) (code int, err error) {
jujud := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "jujud",
Doc: jujudDoc,
})
jujud.Log.Factory = &writerFactory{}
jujud.Register(&BootstrapCommand{})
jujud.Register(&MachineAgent{})
jujud.Register(&UnitAgent{})
code = cmd.Main(jujud, ctx, args[1:])
return code, nil
}