Esempio n. 1
0
func (t *HelpToolCommand) Init(args []string) error {
	tool, err := cmd.ZeroOrOneArgs(args)
	if err == nil {
		t.tool = tool
	}
	return err
}
Esempio n. 2
0
func (s *CmdSuite) TestZeroOrOneArgs(c *C) {

	expectValue := func(args []string, expected string) {
		arg, err := cmd.ZeroOrOneArgs(args)
		c.Assert(arg, Equals, expected)
		c.Assert(err, IsNil)
	}

	expectValue(nil, "")
	expectValue([]string{}, "")
	expectValue([]string{"foo"}, "foo")

	arg, err := cmd.ZeroOrOneArgs([]string{"foo", "bar"})
	c.Assert(arg, Equals, "")
	c.Assert(err, ErrorMatches, `unrecognized args: \["bar"\]`)
}
Esempio n. 3
0
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)
	}
	containerSpec, err := cmd.ZeroOrOneArgs(args)
	if err != nil {
		return err
	}
	if containerSpec == "" {
		return nil
	}
	// container arg can either be 'type:machine' or 'type'
	if c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec); err != nil {
		if !state.IsMachineOrNewContainer(containerSpec) {
			return fmt.Errorf("malformed container argument %q", containerSpec)
		}
		sep := strings.Index(containerSpec, ":")
		c.MachineId = containerSpec[sep+1:]
		c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec[:sep])
	}
	return err
}
Esempio n. 4
0
func (c *SwitchCommand) Init(args []string) (err error) {
	c.EnvName, err = cmd.ZeroOrOneArgs(args)
	return
}
Esempio n. 5
0
func (c *GetEnvironmentCommand) Init(args []string) (err error) {
	c.key, err = cmd.ZeroOrOneArgs(args)
	return
}