本文整理汇总了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
}
示例2: Init
func (t *HelpToolCommand) Init(args []string) error {
tool, err := cmd.ZeroOrOneArgs(args)
if err == nil {
t.tool = tool
}
return err
}
示例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"\]`)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例13: Init
func (c *SwitchCommand) Init(args []string) (err error) {
c.EnvName, err = cmd.ZeroOrOneArgs(args)
return
}
示例14: Init
func (c *GetEnvironmentCommand) Init(args []string) (err error) {
c.key, err = cmd.ZeroOrOneArgs(args)
return
}
示例15: Init
func (c *getCommand) Init(args []string) (err error) {
c.key, err = cmd.ZeroOrOneArgs(args)
return
}