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"\]`) }
func (c *GetEnvironmentCommand) Init(args []string) (err error) { if err := c.EnvCommandBase.EnsureEnvName(); err != nil { return err } c.key, err = cmd.ZeroOrOneArgs(args) return }
func (c *AddMachineCommand) Init(args []string) error { if err := c.EnvCommandBase.EnsureEnvName(); err != nil { return err } 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.EnvironName() + ":" + placement c.Placement, err = instance.ParsePlacement(placement) } if err != nil { return err } return nil }
func (c *SwitchCommand) Init(args []string) (err error) { c.EnvName, err = cmd.ZeroOrOneArgs(args) return }