Esempio n. 1
0
// Main registers subcommands for the jujud 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) {
	jujud := &cmd.SuperCommand{Name: "jujud", Doc: jujudDoc, Log: &cmd.Log{}}
	jujud.Register(&BootstrapCommand{})
	jujud.Register(&MachineAgent{})
	jujud.Register(&UnitAgent{})
	jujud.Register(&VersionCommand{})
	os.Exit(cmd.Main(jujud, cmd.DefaultContext(), args[1:]))
}
Esempio n. 2
0
func main() {
	err := juju.InitJujuHome()
	if err != nil {
		panic(err)
	}
	ctx, err := cmd.DefaultContext()
	if err != nil {
		panic(err)
	}
	c := &NatOutboundCommand{}
	cmd.Main(c, ctx, os.Args[1:])
}
Esempio n. 3
0
// Main registers subcommands for the jujud executable, and hands over control
// to the cmd package.
func jujuDMain(args []string) (code int, err error) {
	jujud := cmd.NewSuperCommand(cmd.SuperCommandParams{
		Name: "jujud",
		Doc:  jujudDoc,
		Log:  &cmd.Log{},
	})
	jujud.Register(&BootstrapCommand{})
	jujud.Register(&MachineAgent{})
	jujud.Register(&UnitAgent{})
	jujud.Register(&cmd.VersionCommand{})
	code = cmd.Main(jujud, cmd.DefaultContext(), args[1:])
	return code, nil
}
Esempio n. 4
0
func (*CmdSuite) TestDestroyEnvironmentCommandConfirmation(c *C) {
	com := new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, nil), IsNil)
	c.Check(com.assumeYes, Equals, false)

	com = new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, []string{"-y"}), IsNil)
	c.Check(com.assumeYes, Equals, true)

	com = new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, []string{"--yes"}), IsNil)
	c.Check(com.assumeYes, Equals, true)

	var stdin, stdout bytes.Buffer
	ctx := cmd.DefaultContext()
	ctx.Stdout = &stdout
	ctx.Stdin = &stdin

	// Ensure confirmation is requested if "-y" is not specified.
	stdin.WriteString("n")
	opc, errc := runCommand(ctx, new(DestroyEnvironmentCommand))
	c.Check(<-errc, ErrorMatches, "Environment destruction aborted")
	c.Check(<-opc, IsNil)
	c.Check(stdout.String(), Matches, "WARNING:.*peckham.*\\(type: dummy\\)(.|\n)*")

	// EOF on stdin: equivalent to answering no.
	stdin.Reset()
	stdout.Reset()
	opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand))
	c.Check(<-opc, IsNil)
	c.Check(<-errc, ErrorMatches, "Environment destruction aborted")

	// "--yes" passed: no confirmation request.
	stdin.Reset()
	stdout.Reset()
	opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "--yes")
	c.Check(<-errc, IsNil)
	c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham")
	c.Check(stdout.String(), Equals, "")

	// Any of casing of "y" and "yes" will confirm.
	for _, answer := range []string{"y", "Y", "yes", "YES"} {
		stdin.Reset()
		stdout.Reset()
		stdin.WriteString(answer)
		opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand))
		c.Check(<-errc, IsNil)
		c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham")
		c.Check(stdout.String(), Matches, "WARNING:.*peckham.*\\(type: dummy\\)(.|\n)*")
	}
}
Esempio n. 5
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) {
	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{})

	os.Exit(cmd.Main(metadatacmd, cmd.DefaultContext(), args[1:]))
}
Esempio n. 6
0
func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
	errc = make(chan error, 1)
	opc = make(chan dummy.Operation, 200)
	dummy.Listen(opc)
	go func() {
		// signal that we're done with this ops channel.
		defer dummy.Listen(nil)

		err := coretesting.InitCommand(com, args)
		if err != nil {
			errc <- err
			return
		}

		err = com.Run(cmd.DefaultContext())
		errc <- err
	}()
	return
}
Esempio n. 7
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) {
	juju := &cmd.SuperCommand{Name: "juju", Doc: jujuDoc, Log: &cmd.Log{}}
	juju.Register(&AddRelationCommand{})
	juju.Register(&AddUnitCommand{})
	juju.Register(&BootstrapCommand{})
	juju.Register(&DeployCommand{})
	juju.Register(&DestroyEnvironmentCommand{})
	juju.Register(&DestroyRelationCommand{}, "remove-relation")
	juju.Register(&DestroyUnitCommand{}, "remove-unit")
	juju.Register(&ExposeCommand{})
	juju.Register(&GetCommand{})
	juju.Register(&ResolvedCommand{})
	juju.Register(&SetCommand{})
	juju.Register(&SCPCommand{})
	juju.Register(&SSHCommand{})
	juju.Register(&StatusCommand{})
	juju.Register(&UnexposeCommand{})
	juju.Register(&UpgradeJujuCommand{})
	os.Exit(cmd.Main(juju, cmd.DefaultContext(), args[1:]))
}
Esempio n. 8
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) {
	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.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic)

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

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

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

	// Error resolution and debugging commands.
	jujucmd.Register(&SCPCommand{})
	jujucmd.Register(&SSHCommand{})
	jujucmd.Register(&ResolvedCommand{})
	jujucmd.Register(&DebugLogCommand{sshCmd: &SSHCommand{}})
	jujucmd.Register(&DebugHooksCommand{})

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

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

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

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

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