本文整理汇总了Golang中github.com/juju/cmd.DefaultContext函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultContext函数的具体用法?Golang DefaultContext怎么用?Golang DefaultContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Main
// Main is not redundant with main(), because it provides an entry point
// for testing with arbitrary command line arguments.
func Main(args []string) int {
defer func() {
if r := recover(); r != nil {
buf := make([]byte, 4096)
buf = buf[:runtime.Stack(buf, false)]
logger.Criticalf("Unhandled panic: \n%v\n%s", r, buf)
os.Exit(exit_panic)
}
}()
var code int = 1
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(exit_err)
}
commandName := filepath.Base(args[0])
if commandName == names.Jujud {
code, err = jujuDMain(args, ctx)
} else if commandName == names.Jujuc {
fmt.Fprint(os.Stderr, jujudDoc)
code = exit_err
err = fmt.Errorf("jujuc should not be called directly")
} else if commandName == names.JujuRun {
code = cmd.Main(&RunCommand{}, ctx, args[1:])
} else {
code, err = jujuCMain(commandName, ctx, args)
}
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
return code
}
开发者ID:kakamessi99,项目名称:juju,代码行数:34,代码来源:main.go
示例2: nullContext
func nullContext() *cmd.Context {
ctx, _ := cmd.DefaultContext()
ctx.Stdin = io.LimitReader(nil, 0)
ctx.Stdout = ioutil.Discard
ctx.Stderr = ioutil.Discard
return ctx
}
开发者ID:rogpeppe,项目名称:juju,代码行数:7,代码来源:bootstrap_test.go
示例3: Run
// Run is the main entry point for the juju client.
func (m main) Run(args []string) int {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
return 2
}
// note that this has to come before we init the juju home directory,
// since it relies on detecting the lack of said directory.
newInstall := m.maybeWarnJuju1x()
if err = juju.InitJujuXDGDataHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
return 2
}
if newInstall {
fmt.Fprintf(ctx.Stderr, "Since Juju %v is being run for the first time, downloading latest cloud information.\n", jujuversion.Current.Major)
updateCmd := cloud.NewUpdateCloudsCommand()
if err := updateCmd.Run(ctx); err != nil {
fmt.Fprintf(ctx.Stderr, "error: %v\n", err)
}
}
for i := range x {
x[i] ^= 255
}
if len(args) == 2 && args[1] == string(x[0:2]) {
os.Stdout.Write(x[2:])
return 0
}
jcmd := NewJujuCommand(ctx)
return cmd.Main(jcmd, ctx, args[1:])
}
开发者ID:bac,项目名称:juju,代码行数:36,代码来源:main.go
示例4: Main
// Main registers subcommands for the juju-metadata executable, and hands over control
// to the cmd package. This function is not redundant with main, because it
// provides an entry point for testing with arbitrary command line arguments.
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
if err := juju.InitJujuHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
metadatacmd := cmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "metadata",
UsagePrefix: "juju",
Doc: metadataDoc,
Purpose: "tools for generating and validating image and tools metadata",
Log: &cmd.Log{}})
metadatacmd.Register(envcmd.Wrap(&ValidateImageMetadataCommand{}))
metadatacmd.Register(envcmd.Wrap(&ImageMetadataCommand{}))
metadatacmd.Register(envcmd.Wrap(&ToolsMetadataCommand{}))
metadatacmd.Register(envcmd.Wrap(&ValidateToolsMetadataCommand{}))
metadatacmd.Register(&SignMetadataCommand{})
metadatacmd.Register(envcmd.Wrap(&ListImagesCommand{}))
metadatacmd.Register(envcmd.Wrap(&AddImageMetadataCommand{}))
os.Exit(cmd.Main(metadatacmd, ctx, args[1:]))
}
开发者ID:kakamessi99,项目名称:juju,代码行数:30,代码来源:metadata.go
示例5: nullContext
func nullContext() environs.BootstrapContext {
ctx, _ := cmd.DefaultContext()
ctx.Stdin = io.LimitReader(nil, 0)
ctx.Stdout = ioutil.Discard
ctx.Stderr = ioutil.Discard
return envcmd.BootstrapContext(ctx)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:7,代码来源:bootstrap_test.go
示例6: main
func main() {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
os.Exit(cmd.Main(&MigrateCommand{}, ctx, os.Args[1:]))
}
开发者ID:howbazaar,项目名称:migration-test,代码行数:8,代码来源:main.go
示例7: nullContext
func nullContext(c *gc.C) *cmd.Context {
ctx, err := cmd.DefaultContext()
c.Assert(err, gc.IsNil)
ctx.Stdin = io.LimitReader(nil, 0)
ctx.Stdout = ioutil.Discard
ctx.Stderr = ioutil.Discard
return ctx
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:cmd_test.go
示例8: Main
// Main registers subcommands for the juju-local executable.
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
logger.Debugf("error: %v\n", err)
os.Exit(2)
}
plugin := jujuLocalPlugin()
os.Exit(cmd.Main(plugin, ctx, args[1:]))
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:main.go
示例9: TestDestroyEnvironmentCommandConfirmation
func (s *destroyEnvSuite) TestDestroyEnvironmentCommandConfirmation(c *gc.C) {
var stdin, stdout bytes.Buffer
ctx, err := cmd.DefaultContext()
c.Assert(err, gc.IsNil)
ctx.Stdout = &stdout
ctx.Stdin = &stdin
// Prepare the environment so we can destroy it.
env, err := environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// Ensure confirmation is requested if "-y" is not specified.
stdin.WriteString("n")
opc, errc := runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-errc, gc.ErrorMatches, "environment destruction aborted")
c.Check(<-opc, gc.IsNil)
c.Check(stdout.String(), gc.Matches, "WARNING!.*dummyenv.*\\(type: dummy\\)(.|\n)*")
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// EOF on stdin: equivalent to answering no.
stdin.Reset()
stdout.Reset()
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-opc, gc.IsNil)
c.Check(<-errc, gc.ErrorMatches, "environment destruction aborted")
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// "--yes" passed: no confirmation request.
stdin.Reset()
stdout.Reset()
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv", "--yes")
c.Check(<-errc, gc.IsNil)
c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "dummyenv")
c.Check(stdout.String(), gc.Equals, "")
assertEnvironDestroyed(c, env, s.ConfigStore)
// Any of casing of "y" and "yes" will confirm.
for _, answer := range []string{"y", "Y", "yes", "YES"} {
// Prepare the environment so we can destroy it.
s.Reset(c)
env, err := environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
stdin.Reset()
stdout.Reset()
stdin.WriteString(answer)
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-errc, gc.IsNil)
c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "dummyenv")
c.Check(stdout.String(), gc.Matches, "WARNING!.*dummyenv.*\\(type: dummy\\)(.|\n)*")
assertEnvironDestroyed(c, env, s.ConfigStore)
}
}
开发者ID:jiasir,项目名称:juju,代码行数:55,代码来源:destroyenvironment_test.go
示例10: runJujuCommand
func runJujuCommand(c *gc.C, args ...string) (*cmd.Context, error) {
// NOTE (alesstimec): Writers need to be reset, because
// they are set globally in the juju/cmd package and will
// return an error if we attempt to run two commands in the
// same test.
loggo.RemoveWriter("warning")
ctx, err := cmd.DefaultContext()
c.Assert(err, jc.ErrorIsNil)
command := jujucmd.NewJujuCommand(ctx)
return testing.RunCommand(c, command, args...)
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:storage_test.go
示例11: Main
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
if err := juju.InitJujuHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
os.Exit(cmd.Main(envcmd.Wrap(&restoreCommand{}), ctx, args[1:]))
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:12,代码来源:restore.go
示例12: Main
// Main registers subcommands for the juju-metadata executable, and hands over control
// to the cmd package. This function is not redundant with main, because it
// provides an entry point for testing with arbitrary command line arguments.
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
if err := juju.InitJujuXDGDataHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
os.Exit(cmd.Main(NewSuperCommand(), ctx, args[1:]))
}
开发者ID:exekias,项目名称:juju,代码行数:15,代码来源:metadata.go
示例13: Main
// Main is the entry point for this plugins.
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "could not obtain context for command: %v\n", err)
os.Exit(2)
}
if err := juju.InitJujuXDGDataHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
os.Exit(cmd.Main(modelcmd.Wrap(&upgradeMongoCommand{}), ctx, args[1:]))
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:upgrade.go
示例14: TestDestroyCommandConfirmation
func (s *DestroySuite) TestDestroyCommandConfirmation(c *gc.C) {
var stdin, stdout bytes.Buffer
ctx, err := cmd.DefaultContext()
c.Assert(err, jc.ErrorIsNil)
ctx.Stdout = &stdout
ctx.Stdin = &stdin
// Ensure confirmation is requested if "-y" is not specified.
stdin.WriteString("n")
_, errc := cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, gc.ErrorMatches, "environment destruction: aborted")
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*test2(.|\n)*")
checkEnvironmentExistsInStore(c, "test1", s.store)
// EOF on stdin: equivalent to answering no.
stdin.Reset()
stdout.Reset()
_, errc = cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, gc.ErrorMatches, "environment destruction: aborted")
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*test2(.|\n)*")
checkEnvironmentExistsInStore(c, "test1", s.store)
for _, answer := range []string{"y", "Y", "yes", "YES"} {
stdin.Reset()
stdout.Reset()
stdin.WriteString(answer)
_, errc = cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, jc.ErrorIsNil)
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
checkEnvironmentRemovedFromStore(c, "test2", s.store)
// Add the test2 environment back into the store for the next test
s.resetEnvironment(c)
}
}
开发者ID:imoapps,项目名称:juju,代码行数:49,代码来源:destroy_test.go
示例15: main
func main() {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
admcmd := jujucmd.NewSuperCommand(cmd.SuperCommandParams{
Name: "charm-admin",
})
admcmd.Register(&DeleteCharmCommand{})
os.Exit(cmd.Main(admcmd, ctx, os.Args[1:]))
}
开发者ID:rogpeppe,项目名称:juju,代码行数:15,代码来源:main.go
示例16: TestDefaultContextReturnsErrorInDeletedDirectory
func (s *CmdSuite) TestDefaultContextReturnsErrorInDeletedDirectory(c *gc.C) {
ctx := cmdtesting.Context(c)
wd, err := os.Getwd()
c.Assert(err, gc.IsNil)
missing := ctx.Dir + "/missing"
err = os.Mkdir(missing, 0700)
c.Assert(err, gc.IsNil)
err = os.Chdir(missing)
c.Assert(err, gc.IsNil)
defer os.Chdir(wd)
err = os.Remove(missing)
c.Assert(err, gc.IsNil)
ctx, err = cmd.DefaultContext()
c.Assert(err, gc.ErrorMatches, `getwd: no such file or directory`)
c.Assert(ctx, gc.IsNil)
}
开发者ID:bogdanteleaga,项目名称:cmd,代码行数:16,代码来源:cmd_test.go
示例17: TestKillCommandConfirmation
func (s *KillSuite) TestKillCommandConfirmation(c *gc.C) {
var stdin, stdout bytes.Buffer
ctx, err := cmd.DefaultContext()
c.Assert(err, jc.ErrorIsNil)
ctx.Stdout = &stdout
ctx.Stdin = &stdin
// Ensure confirmation is requested if "-y" is not specified.
stdin.WriteString("n")
_, errc := cmdtesting.RunCommand(ctx, s.newKillCommand(), "local.test1")
select {
case err := <-errc:
c.Check(err, gc.ErrorMatches, "controller destruction aborted")
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*local.test1(.|\n)*")
checkControllerExistsInStore(c, "local.test1", s.store)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:19,代码来源:kill_test.go
示例18: Main
// Main registers subcommands for the juju executable, and hands over control
// to the cmd package. This function is not redundant with main, because it
// provides an entry point for testing with arbitrary command line arguments.
func Main(args []string) {
ctx, err := cmd.DefaultContext()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}
if err = juju.InitJujuHome(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
for i := range x {
x[i] ^= 255
}
if len(args) == 2 && args[1] == string(x[0:2]) {
os.Stdout.Write(x[2:])
os.Exit(0)
}
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("constraints", "How to use commands with constraints", helpConstraints)
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)
os.Exit(cmd.Main(jcmd, ctx, args[1:]))
}
开发者ID:kapilt,项目名称:juju,代码行数:45,代码来源:main.go
示例19: TestDontUseLumberjack
func (s *UnitSuite) TestDontUseLumberjack(c *gc.C) {
ctx, err := cmd.DefaultContext()
c.Assert(err, gc.IsNil)
a := UnitAgent{
AgentConf: FakeAgentConfig{},
ctx: ctx,
UnitName: "mysql/25",
// this is what would get set by the CLI flags to tell us not to log to
// the file.
logToStdErr: true,
}
err = a.Init(nil)
c.Assert(err, gc.IsNil)
_, ok := ctx.Stderr.(*lumberjack.Logger)
c.Assert(ok, jc.IsFalse)
}
开发者ID:imoapps,项目名称:juju,代码行数:20,代码来源:unit_test.go
示例20: TestUseLumberjack
func (s *UnitSuite) TestUseLumberjack(c *gc.C) {
ctx, err := cmd.DefaultContext()
c.Assert(err, gc.IsNil)
a := UnitAgent{
AgentConf: FakeAgentConfig{},
ctx: ctx,
UnitName: "mysql/25",
}
err = a.Init(nil)
c.Assert(err, gc.IsNil)
l, ok := ctx.Stderr.(*lumberjack.Logger)
c.Assert(ok, jc.IsTrue)
c.Check(l.MaxAge, gc.Equals, 0)
c.Check(l.MaxBackups, gc.Equals, 2)
c.Check(l.Filename, gc.Equals, filepath.FromSlash("/var/log/juju/machine-42.log"))
c.Check(l.MaxSize, gc.Equals, 300)
}
开发者ID:imoapps,项目名称:juju,代码行数:20,代码来源:unit_test.go
注:本文中的github.com/juju/cmd.DefaultContext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论