// Init is defined on the cmd.Command interface. It checks the
// arguments for sanity and sets up the command to run.
194074
func (c *ListCommand) Init(args []string) error {
	// No arguments are accepted, just flags.
	err := cmd.CheckEmpty(args)
	if err != nil {
		return err
	}

	// Validate space name, if given and store as tag.
	c.spaceTag = nil
	if c.SpaceName != "" {
		tag, err := c.ValidateSpace(c.SpaceName)
		if err != nil {
			c.SpaceName = ""
			return err
		}
		c.spaceTag = &tag
	}
	return nil
}
885510
func (c *configCommand) Init(args []string) error {
	// If there are arguments provided to reset, we turn it into a slice of
	// strings and verify them. If there is one or more valid keys to reset and
	// no other errors initializing the command, c.resetDefaults will be called
	// in c.Run.
	if err := c.parseResetKeys(); err != nil {
		return errors.Trace(err)
	}

	switch len(args) {
	case 0:
		return c.handleZeroArgs()
	case 1:
		return c.handleOneArg(args[0])
	default:
		return c.handleArgs(args)
	}
}
278491
func (c *BootstrapCommand) Init(args []string) error {
	if len(args) == 0 {
		return errors.New("bootstrap-params file must be specified")
	}
	if err := cmd.CheckEmpty(args[1:]); err != nil {
		return err
	}
	c.BootstrapParamsFile = args[0]
	return c.AgentConf.CheckArgs(args[1:])
}
1155513
func (c *destroyCommand) Init(args []string) error {
	if c.destroyStorage && c.releaseStorage {
		return errors.New("--destroy-storage and --release-storage cannot both be specified")
	}
	return c.destroyCommandBase.Init(args)
}
2117
func (c *deleteImageMetadataCommand) Init(args []string) (err error) {
	if len(args) == 0 {
		return errors.New("image ID must be supplied when deleting image metadata")
	}
	if len(args) != 1 {
		return errors.New("only one image ID can be supplied as an argument to this command")
	}
	c.ImageId = args[0]
	return nil
}
1332391
func (c *addCommand) Init(args []string) error {
	if len(args) == 0 {
		return errors.Errorf("no username supplied")
	}

	c.User, args = args[0], args[1:]
	if len(args) > 0 {
		c.DisplayName, args = args[0], args[1:]
	}
	return cmd.CheckEmpty(args)
}
345123
func (c *importKeysCommand) Init(args []string) error {
	if len(args) == 0 {
		return errors.New("no ssh key id specified")
	}
	c.sshKeyIds = args
	for _, k := range c.sshKeyIds {
		if len(k) < 3 {
			return errors.NotValidf("%q key ID", k)
		}
		switch k[:3] {
		case "lp:", "gh:":
		default:
			return errors.NewNotSupported(nil,
				fmt.Sprintf("prefix in Key ID %q not supported, only lp: and gh: are allowed", k))
		}
	}
	return nil
}
397973
func (c *removeCommand) Init(args []string) error {
	if len(args) == 0 {
		return errors.Errorf("no offers specified")
	}
	c.offers = args
	return nil
}
1335862
func (c *slaCommand) Init(args []string) error {
	if len(args) < 1 {
		return nil
	}
	c.Level = args[0]
	return c.ModelCommandBase.Init(args[1:])
}
923125
func (c *upgradeGUICommand) Init(args []string) error {
	if len(args) == 1 {
		if c.list {
			return errors.New("cannot provide arguments if --list is provided")
		}
		c.versOrPath = args[0]
		return nil
	}
	return cmd.CheckEmpty(args)
}
922195
func (c *removeKeysCommand) Init(args []string) error {
	switch len(args) {
	case 0:
		return errors.New("no ssh key id specified")
	default:
		c.keyIds = args
	}
	return nil
}
858959
func (c *bundleDiffCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("no bundle specified")
	}
	c.bundle = args[0]
	// UseExisting is assumed for diffing.
	_, mapping, err := parseMachineMap(c.machineMap)
	if err != nil {
		return errors.Annotate(err, "error in --map-machines")
	}
	c.bundleMachines = mapping

	return cmd.CheckEmpty(args[1:])
}
245373
func (cmd *Cmd) Init(plugins ...Plugin) {
	if cmd.PreLoop == nil {
		cmd.PreLoop = func() {}
	}
	if cmd.PostLoop == nil {
		cmd.PostLoop = func() {}
	}
	if cmd.PreCmd == nil {
		cmd.PreCmd = func(string) {}
	}
	if cmd.PostCmd == nil {
		cmd.PostCmd = func(line string, stop bool) bool { return stop }
	}
	if cmd.OneCmd == nil {
		cmd.OneCmd = cmd.oneCmd
	}
	if cmd.EmptyLine == nil {
		cmd.EmptyLine = func() {}
	}
	if cmd.Default == nil {
		cmd.Default = func(line string) { fmt.Printf("invalid command: %v\n", line) }
	}
	if cmd.OnChange == nil {
		cmd.OnChange = func(name string, oldv, newv interface{}) interface{} { return newv }
	}
	if cmd.Interrupt == nil {
		cmd.Interrupt = func(sig os.Signal) bool { return true }
	}
	if cmd.Help == nil {
		cmd.Help = cmd.help
	}
	cmd.context = internal.NewContext()
	cmd.context.PushScope(nil, nil)

	cmd.Commands = make(map[string]Command)
	cmd.Add(Command{"help", `list available commands`, func(line string) bool {
		return cmd.Help(line)
	}, nil})
	cmd.Add(Command{"echo", `echo input line`, cmd.command_echo, nil})
	cmd.Add(Command{"go", `go cmd: asynchronous execution of cmd, or 'go [--start|--wait]'`, cmd.command_go, nil})
	cmd.Add(Command{"time", `time [starttime]`, cmd.command_time, nil})
	cmd.Add(Command{"output", `output [filename|--]`, cmd.command_output, nil})
	cmd.Add(Command{"exit", `exit program`, cmd.command_exit, nil})

	for _, p := range plugins {
		if err := p.PluginInit(cmd, cmd.context); err != nil {
			panic("plugin initialization failed: " + err.Error())
		}
	}

	cmd.SetVar("echo", cmd.Echo)
	cmd.SetVar("print", !cmd.Silent)
	cmd.SetVar("timing", cmd.Timing)
}
402460
func (c *showMachineCommand) Init(args []string) error {
	c.machineIds = args
	return nil
}
586820
func (c *checkConnectionCommand) Init(args []string) error {
	if len(args) == 0 {
		return &util.FatalError{"agent-name argument is required"}
	}
	agentName, args := args[0], args[1:]
	if err := cmd.CheckEmpty(args); err != nil {
		return err
	}
	tag, err := names.ParseTag(agentName)
	if err != nil {
		return errors.Annotatef(err, "agent-name")
	}
	if tag.Kind() != "machine" && tag.Kind() != "unit" {
		return &util.FatalError{"agent-name must be a machine or unit tag"}
	}
	err = c.config.ReadConfig(agentName)
	if err != nil {
		return errors.Trace(err)
	}
	c.agentName = agentName
	return nil
}
562428
func (c *NetworkGetCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("no arguments specified")
	}
	c.bindingName = args[0]
	if c.bindingName == "" {
		return fmt.Errorf("no binding name specified")
	}
	if c.bindAddress {
		c.keys = append(c.keys, bindAddressKey)
	}
	if c.ingressAddress {
		c.keys = append(c.keys, ingressAddressKey)
	}
	if c.egressSubnets {
		c.keys = append(c.keys, egressSubnetsKey)
	}

	return cmd.CheckEmpty(args[1:])
}
188523
func (c *ActionGetCommand) Init(args []string) error {
	if len(args) > 0 {
		err := cmd.CheckEmpty(args[1:])
		if err != nil {
			return err
		}
		c.keys = strings.Split(args[0], ".")
	}
	return nil
}