当前位置: 首页>>代码示例>>Golang>>正文


Golang cmd.ZeroOrOneArgs函数代码示例

本文整理汇总了Golang中github.com/juju/cmd.ZeroOrOneArgs函数的典型用法代码示例。如果您正苦于以下问题:Golang ZeroOrOneArgs函数的具体用法?Golang ZeroOrOneArgs怎么用?Golang ZeroOrOneArgs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ZeroOrOneArgs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Init

// 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
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:list.go

示例2: Init

func (t *HelpToolCommand) Init(args []string) error {
	tool, err := cmd.ZeroOrOneArgs(args)
	if err == nil {
		t.tool = tool
	}
	return err
}
开发者ID:kapilt,项目名称:juju,代码行数:7,代码来源:helptool.go

示例3: TestZeroOrOneArgs

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"\]`)
}
开发者ID:bogdanteleaga,项目名称:cmd,代码行数:16,代码来源:cmd_test.go

示例4: Init

// 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
}
开发者ID:kat-co,项目名称:juju,代码行数:9,代码来源:login.go

示例5: Init

func (c *StorageListCommand) Init(args []string) (err error) {
	storageName, err := cmd.ZeroOrOneArgs(args)
	if err != nil {
		return err
	}
	c.storageName = storageName
	return nil
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:storage-list.go

示例6: Init

// 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
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:change_password.go

示例7: Init

func (c *listCredentialsCommand) Init(args []string) error {
	cloudName, err := cmd.ZeroOrOneArgs(args)
	if err != nil {
		return errors.Trace(err)
	}
	c.cloudName = cloudName
	return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:listcredentials.go

示例8: Init

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
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:storage-get.go

示例9: Init

// 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
}
开发者ID:bac,项目名称:juju,代码行数:17,代码来源:create.go

示例10: Init

// 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
}
开发者ID:kat-co,项目名称:juju,代码行数:47,代码来源:configcommand.go

示例11: Init

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
}
开发者ID:rogpeppe,项目名称:juju,代码行数:18,代码来源:addmachine.go

示例12: Init

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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:21,代码来源:add.go

示例13: Init

func (c *SwitchCommand) Init(args []string) (err error) {
	c.EnvName, err = cmd.ZeroOrOneArgs(args)
	return
}
开发者ID:jiasir,项目名称:juju,代码行数:4,代码来源:switch.go

示例14: Init

func (c *GetEnvironmentCommand) Init(args []string) (err error) {
	c.key, err = cmd.ZeroOrOneArgs(args)
	return
}
开发者ID:rogpeppe,项目名称:juju,代码行数:4,代码来源:environment.go

示例15: Init

func (c *getCommand) Init(args []string) (err error) {
	c.key, err = cmd.ZeroOrOneArgs(args)
	return
}
开发者ID:imoapps,项目名称:juju,代码行数:4,代码来源:get.go


注:本文中的github.com/juju/cmd.ZeroOrOneArgs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。