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


Golang FlagSet.Parse方法代码示例

本文整理汇总了Golang中launchpad/net/gnuflag.FlagSet.Parse方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.Parse方法的具体用法?Golang FlagSet.Parse怎么用?Golang FlagSet.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在launchpad/net/gnuflag.FlagSet的用法示例。


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

示例1: Init

func (c *DestroyEnvironmentCommand) Init(f *gnuflag.FlagSet, args []string) error {
	addEnvironFlags(&c.EnvName, f)
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:7,代码来源:destroyenvironment.go

示例2: Init

func (v *VersionCommand) Init(f *gnuflag.FlagSet, args []string) error {
	v.out.AddFlags(f, "smart", cmd.DefaultFormatters)
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:7,代码来源:version.go

示例3: Init

func (c *RelationGetCommand) Init(f *gnuflag.FlagSet, args []string) error {
	// TODO FWER implement --format shell lp:1033511
	c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
	f.Var(newRelationIdValue(c.ctx, &c.RelationId), "r", "specify a relation by id")
	if err := f.Parse(true, args); err != nil {
		return err
	}
	if c.RelationId == -1 {
		return fmt.Errorf("no relation id specified")
	}
	args = f.Args()
	c.Key = ""
	if len(args) > 0 {
		if c.Key = args[0]; c.Key == "-" {
			c.Key = ""
		}
		args = args[1:]
	}
	if name, found := c.ctx.RemoteUnitName(); found {
		c.UnitName = name
	}
	if len(args) > 0 {
		c.UnitName = args[0]
		args = args[1:]
	}
	if c.UnitName == "" {
		return fmt.Errorf("no unit id specified")
	}
	return cmd.CheckEmpty(args)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:30,代码来源:relation-get.go

示例4: Init

func (c *portCommand) Init(f *gnuflag.FlagSet, args []string) error {
	if err := f.Parse(true, args); err != nil {
		return err
	}
	args = f.Args()
	if args == nil {
		return errors.New("no port specified")
	}
	parts := strings.Split(args[0], "/")
	if len(parts) > 2 {
		return fmt.Errorf("expected %s; got %q", portFormat, args[0])
	}
	port, err := strconv.Atoi(parts[0])
	if err != nil {
		return badPort(parts[0])
	}
	if port < 1 || port > 65535 {
		return badPort(port)
	}
	protocol := "tcp"
	if len(parts) == 2 {
		protocol = strings.ToLower(parts[1])
		if protocol != "tcp" && protocol != "udp" {
			return fmt.Errorf(`protocol must be "tcp" or "udp"; got %q`, protocol)
		}
	}
	c.Port = port
	c.Protocol = protocol
	return cmd.CheckEmpty(args[1:])
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:30,代码来源:ports.go

示例5: handleFlags

func (m *Manager) handleFlags(command Command, name string, args []string) (Command, []string, error) {
	var flagset *gnuflag.FlagSet
	if flagged, ok := command.(FlaggedCommand); ok {
		flagset = flagged.Flags()
	} else {
		flagset = gnuflag.NewFlagSet(name, gnuflag.ExitOnError)
	}
	var helpRequested bool
	flagset.SetOutput(m.stderr)
	if flagset.Lookup("help") == nil {
		flagset.BoolVar(&helpRequested, "help", false, "Display help and exit")
	}
	if flagset.Lookup("h") == nil {
		flagset.BoolVar(&helpRequested, "h", false, "Display help and exit")
	}
	err := flagset.Parse(true, args)
	if err != nil {
		return nil, nil, err
	}
	if helpRequested {
		command = m.Commands["help"]
		args = []string{name}
	} else {
		args = flagset.Args()
	}
	return command, args, nil
}
开发者ID:4eek,项目名称:tsuru,代码行数:27,代码来源:cmd.go

示例6: Init

func (c *RemoteCommand) Init(f *gnuflag.FlagSet, args []string) error {
	f.StringVar(&c.msg, "error", "", "if set, fail")
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:7,代码来源:main_test.go

示例7: Init

func (c *BootstrapCommand) Init(f *gnuflag.FlagSet, args []string) error {
	addEnvironFlags(&c.EnvName, f)
	f.BoolVar(&c.UploadTools, "upload-tools", false, "upload local version of tools before bootstrapping")
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:8,代码来源:bootstrap.go

示例8: Init

func (c *RpcCommand) Init(f *gnuflag.FlagSet, args []string) error {
	f.StringVar(&c.Value, "value", "", "doc")
	f.BoolVar(&c.Slow, "slow", false, "doc")
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:8,代码来源:server_test.go

示例9: Init

func (c *TestCommand) Init(f *gnuflag.FlagSet, args []string) error {
	if !c.Minimal {
		f.StringVar(&c.Option, "option", "", "option-doc")
	}
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:9,代码来源:util_test.go

示例10: ParseArgs

// ParseArgs encapsulate the parsing of the args so this function can be
// called from the testing module too.
func ParseArgs(c Command, f *gnuflag.FlagSet, args []string) error {
	// If the command is a SuperCommand, we want to parse the args with
	// allowIntersperse=false (i.e. the first parameter to Parse.  This will
	// mean that the args may contain other options that haven't been defined
	// yet, and that only options that relate to the SuperCommand itself can
	// come prior to the subcommand name.
	_, isSuperCommand := c.(*SuperCommand)
	return f.Parse(!isSuperCommand, args)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:11,代码来源:cmd.go

示例11: Init

// Init initializes the command for running.
func (a *MachineAgent) Init(f *gnuflag.FlagSet, args []string) error {
	a.Conf.addFlags(f)
	f.StringVar(&a.MachineId, "machine-id", "", "id of the machine to run")
	if err := f.Parse(true, args); err != nil {
		return err
	}
	if !state.IsMachineId(a.MachineId) {
		return fmt.Errorf("--machine-id option must be set, and expects a non-negative integer")
	}
	return a.Conf.checkArgs(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:12,代码来源:machine.go

示例12: Init

func (c *StatusCommand) Init(f *gnuflag.FlagSet, args []string) error {
	addEnvironFlags(&c.EnvName, f)
	c.out.AddFlags(f, "yaml", map[string]cmd.Formatter{
		"yaml": cmd.FormatYaml,
		"json": cmd.FormatJson,
	})
	if err := f.Parse(true, args); err != nil {
		return err
	}
	return cmd.CheckEmpty(f.Args())
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:11,代码来源:status.go

示例13: initEnvCommandBase

func initEnvCommandBase(c *gc.C, name string) *envcmd.EnvCommandBase {
	var flags gnuflag.FlagSet
	var cmd envcmd.EnvCommandBase
	cmd.SetFlags(&flags)
	var args []string
	if name != "" {
		args = []string{"-e", name}
	}
	err := flags.Parse(false, args)
	c.Assert(err, gc.IsNil)
	return &cmd
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:environmentcommand_test.go

示例14: Init

func (c *DestroyRelationCommand) Init(f *gnuflag.FlagSet, args []string) error {
	addEnvironFlags(&c.EnvName, f)
	if err := f.Parse(true, args); err != nil {
		return err
	}
	args = f.Args()
	if len(args) != 2 {
		return fmt.Errorf("a relation must involve two services")
	}
	c.Endpoints = args
	return nil
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:12,代码来源:destroyrelation.go

示例15: Init

func (c *UnexposeCommand) Init(f *gnuflag.FlagSet, args []string) error {
	addEnvironFlags(&c.EnvName, f)
	if err := f.Parse(true, args); err != nil {
		return err
	}
	args = f.Args()
	if len(args) == 0 {
		return errors.New("no service name specified")
	}
	c.ServiceName = args[0]
	return cmd.CheckEmpty(args[1:])
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:12,代码来源:unexpose.go


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