Beispiel #1
0
func nullContext() *cmd.Context {
	ctx, _ := cmd.DefaultContext()
	ctx.Stdin = io.LimitReader(nil, 0)
	ctx.Stdout = ioutil.Discard
	ctx.Stderr = ioutil.Discard
	return ctx
}
Beispiel #2
0
// 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(&ValidateImageMetadataCommand{})
	metadatacmd.Register(&ImageMetadataCommand{})
	metadatacmd.Register(&ToolsMetadataCommand{})
	metadatacmd.Register(&ValidateToolsMetadataCommand{})
	metadatacmd.Register(&SignMetadataCommand{})

	os.Exit(cmd.Main(metadatacmd, ctx, args[1:]))
}
Beispiel #3
0
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
}
Beispiel #4
0
// 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:]))
}
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)
	}
}
Beispiel #6
0
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(&restoreCommand{}, ctx, args[1:]))
}
Beispiel #7
0
func main() {
	ctx, err := cmd.DefaultContext()
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(2)
	}

	admcmd := cmd.NewSuperCommand(cmd.SuperCommandParams{
		Name: "charm-admin",
		Log:  &cmd.Log{},
	})

	admcmd.Register(&DeleteCharmCommand{})

	os.Exit(cmd.Main(admcmd, ctx, os.Args[1:]))
}
Beispiel #8
0
func (s *CmdSuite) TestDefaultContextReturnsErrorInDeletedDirectory(c *gc.C) {
	ctx := testing.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)
}
Beispiel #9
0
// Main is not redundant with main(), because it provides an entry point
// for testing with arbitrary command line arguments.
func Main(args []string) {
	var code int = 1
	ctx, err := cmd.DefaultContext()
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(2)
	}
	commandName := filepath.Base(args[0])
	if commandName == "jujud" {
		code, err = jujuDMain(args, ctx)
	} else if commandName == "jujuc" {
		fmt.Fprint(os.Stderr, jujudDoc)
		code = 2
		err = fmt.Errorf("jujuc should not be called directly")
	} else if commandName == "juju-run" {
		code = cmd.Main(&RunCommand{}, ctx, args[1:])
	} else {
		code, err = jujuCMain(commandName, args)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
	}
	os.Exit(code)
}
Beispiel #10
0
// 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)
	}
	jujucmd := cmd.NewSuperCommand(cmd.SuperCommandParams{
		Name:            "juju",
		Doc:             jujuDoc,
		Log:             &cmd.Log{},
		MissingCallback: RunPlugin,
	})
	jujucmd.AddHelpTopic("basics", "Basic commands", helpBasics)
	jujucmd.AddHelpTopic("local-provider", "How to configure a local (LXC) provider",
		helpProviderStart+helpLocalProvider+helpProviderEnd)
	jujucmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider",
		helpProviderStart+helpOpenstackProvider+helpProviderEnd, "openstack")
	jujucmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider",
		helpProviderStart+helpEC2Provider+helpProviderEnd, "ec2", "aws", "amazon")
	jujucmd.AddHelpTopic("hpcloud-provider", "How to configure an HP Cloud provider",
		helpProviderStart+helpHPCloud+helpProviderEnd, "hpcloud", "hp-cloud")
	jujucmd.AddHelpTopic("azure-provider", "How to configure a Windows Azure provider",
		helpProviderStart+helpAzureProvider+helpProviderEnd, "azure")
	jujucmd.AddHelpTopic("constraints", "How to use commands with constraints", helpConstraints)
	jujucmd.AddHelpTopic("glossary", "Glossary of terms", helpGlossary)
	jujucmd.AddHelpTopic("logging", "How Juju handles logging", helpLogging)

	jujucmd.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic)

	// Creation commands.
	jujucmd.Register(wrap(&BootstrapCommand{}))
	jujucmd.Register(wrap(&AddMachineCommand{}))
	jujucmd.Register(wrap(&DeployCommand{}))
	jujucmd.Register(wrap(&AddRelationCommand{}))
	jujucmd.Register(wrap(&AddUnitCommand{}))

	// Destruction commands.
	jujucmd.Register(wrap(&DestroyMachineCommand{}))
	jujucmd.Register(wrap(&DestroyRelationCommand{}))
	jujucmd.Register(wrap(&DestroyServiceCommand{}))
	jujucmd.Register(wrap(&DestroyUnitCommand{}))
	jujucmd.Register(wrap(&DestroyEnvironmentCommand{}))

	// Reporting commands.
	jujucmd.Register(wrap(&StatusCommand{}))
	jujucmd.Register(wrap(&SwitchCommand{}))
	jujucmd.Register(wrap(&EndpointCommand{}))

	// Error resolution and debugging commands.
	jujucmd.Register(wrap(&RunCommand{}))
	jujucmd.Register(wrap(&SCPCommand{}))
	jujucmd.Register(wrap(&SSHCommand{}))
	jujucmd.Register(wrap(&ResolvedCommand{}))
	jujucmd.Register(wrap(&DebugLogCommand{}))
	jujucmd.Register(wrap(&DebugHooksCommand{}))
	jujucmd.Register(wrap(&RetryProvisioningCommand{}))

	// Configuration commands.
	jujucmd.Register(wrap(&InitCommand{}))
	jujucmd.Register(wrap(&GetCommand{}))
	jujucmd.Register(wrap(&SetCommand{}))
	jujucmd.Register(wrap(&UnsetCommand{}))
	jujucmd.Register(wrap(&GetConstraintsCommand{}))
	jujucmd.Register(wrap(&SetConstraintsCommand{}))
	jujucmd.Register(wrap(&GetEnvironmentCommand{}))
	jujucmd.Register(wrap(&SetEnvironmentCommand{}))
	jujucmd.Register(wrap(&UnsetEnvironmentCommand{}))
	jujucmd.Register(wrap(&ExposeCommand{}))
	jujucmd.Register(wrap(&SyncToolsCommand{}))
	jujucmd.Register(wrap(&UnexposeCommand{}))
	jujucmd.Register(wrap(&UpgradeJujuCommand{}))
	jujucmd.Register(wrap(&UpgradeCharmCommand{}))

	// Charm publishing commands.
	jujucmd.Register(wrap(&PublishCommand{}))

	// Charm tool commands.
	jujucmd.Register(wrap(&HelpToolCommand{}))

	// Manage authorized ssh keys.
	jujucmd.Register(wrap(NewAuthorizedKeysCommand()))

	// Manage state server availability.
	// TODO: enable once the backend is ready for it.
	jujucmd.Register(wrap(&EnsureAvailabilityCommand{}))

	// Common commands.
	jujucmd.Register(wrap(&cmd.VersionCommand{}))

	os.Exit(cmd.Main(jujucmd, ctx, args[1:]))
}