// Init implements Command.Init. func (c *listCommand) Init(args []string) (err error) { c.modelName, err = cmd.ZeroOrOneArgs(args) if err != nil { return err } return err }
func (t *HelpToolCommand) Init(args []string) error { tool, err := cmd.ZeroOrOneArgs(args) if err == nil { t.tool = tool } return err }
func (s *CmdSuite) TestZeroOrOneArgs(c *gc.C) { expectValue := func(args []string, expected string) { arg, err := cmd.ZeroOrOneArgs(args) c.Assert(arg, gc.Equals, expected) c.Assert(err, gc.IsNil) } expectValue(nil, "") expectValue([]string{}, "") expectValue([]string{"foo"}, "foo") arg, err := cmd.ZeroOrOneArgs([]string{"foo", "bar"}) c.Assert(arg, gc.Equals, "") c.Assert(err, gc.ErrorMatches, `unrecognized args: \["bar"\]`) }
// Init implements Command.Init. func (c *loginCommand) Init(args []string) error { var err error c.User, err = cmd.ZeroOrOneArgs(args) if err != nil { return errors.Trace(err) } return nil }
func (c *StorageListCommand) Init(args []string) (err error) { storageName, err := cmd.ZeroOrOneArgs(args) if err != nil { return err } c.storageName = storageName return nil }
// Init implements Command.Init. func (c *ChangePasswordCommand) Init(args []string) error { var err error c.User, err = cmd.ZeroOrOneArgs(args) if c.User == "" && c.OutPath != "" { return errors.New("output is only a valid option when changing another user's password") } return err }
func (c *listCredentialsCommand) Init(args []string) error { cloudName, err := cmd.ZeroOrOneArgs(args) if err != nil { return errors.Trace(err) } c.cloudName = cloudName return nil }
func (c *StorageGetCommand) Init(args []string) error { if c.storageTag == (names.StorageTag{}) { return errors.New("no storage instance specified") } key, err := cmd.ZeroOrOneArgs(args) if err != nil { return err } c.key = key return nil }
// Init implements Command.Init. func (c *createCommand) Init(args []string) error { notes, err := cmd.ZeroOrOneArgs(args) if err != nil { return err } c.Notes = notes if c.Filename != notset && c.NoDownload { return errors.Errorf("cannot mix --no-download and --filename") } if c.Filename == "" { return errors.Errorf("missing filename") } return nil }
// Init implements part of the cmd.Command interface. func (c *configCommand) Init(args []string) error { if c.reset { // We're doing resetConfig. if len(args) == 0 { return errors.New("no keys specified") } for _, k := range args { if k == config.AgentVersionKey { return errors.Errorf("agent-version cannot be reset") } } c.keys = args c.action = c.resetConfig return nil } if len(args) > 0 && strings.Contains(args[0], "=") { // We're setting values. options, err := keyvalues.Parse(args, true) if err != nil { return errors.Trace(err) } c.values = make(attributes) for k, v := range options { if k == config.AgentVersionKey { return errors.Errorf(`agent-version must be set via "upgrade-juju"`) } c.values[k] = v } c.action = c.setConfig return nil } val, err := cmd.ZeroOrOneArgs(args) if err != nil { return errors.New("can only retrieve a single value, or all values") } // We're doing getConfig. if val != "" { c.keys = []string{val} } c.action = c.getConfig return nil }
func (c *AddMachineCommand) Init(args []string) error { if c.Constraints.Container != nil { return fmt.Errorf("container constraint %q not allowed when adding a machine", *c.Constraints.Container) } placement, err := cmd.ZeroOrOneArgs(args) if err != nil { return err } c.Placement, err = instance.ParsePlacement(placement) if err == instance.ErrPlacementScopeMissing { placement = c.EnvName + ":" + placement c.Placement, err = instance.ParsePlacement(placement) } if err != nil { return err } return nil }
func (c *addCommand) Init(args []string) error { if c.Constraints.Container != nil { return fmt.Errorf("container constraint %q not allowed when adding a machine", *c.Constraints.Container) } placement, err := cmd.ZeroOrOneArgs(args) if err != nil { return err } c.Placement, err = instance.ParsePlacement(placement) if err == instance.ErrPlacementScopeMissing { placement = "model-uuid" + ":" + placement c.Placement, err = instance.ParsePlacement(placement) } if err != nil { return err } if c.NumMachines > 1 && c.Placement != nil && c.Placement.Directive != "" { return fmt.Errorf("cannot use -n when specifying a placement directive") } return nil }
func (c *switchCommand) Init(args []string) error { var err error c.Target, err = cmd.ZeroOrOneArgs(args) return err }
func (c *SwitchCommand) Init(args []string) (err error) { c.EnvName, err = cmd.ZeroOrOneArgs(args) return }
func (c *GetEnvironmentCommand) Init(args []string) (err error) { c.key, err = cmd.ZeroOrOneArgs(args) return }
func (c *getCommand) Init(args []string) (err error) { c.key, err = cmd.ZeroOrOneArgs(args) return }
func (c *UserInfoCommand) Init(args []string) (err error) { c.Username, err = cmd.ZeroOrOneArgs(args) return err }