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


Golang gnuflag.NewFlagSet函数代码示例

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


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

示例1: TestMergeFlagSet

func (s *S) TestMergeFlagSet(c *check.C) {
	var x, y bool
	fs1 := gnuflag.NewFlagSet("x", gnuflag.ExitOnError)
	fs1.BoolVar(&x, "x", false, "Something")
	fs2 := gnuflag.NewFlagSet("y", gnuflag.ExitOnError)
	fs2.BoolVar(&y, "y", false, "Something")
	ret := MergeFlagSet(fs1, fs2)
	c.Assert(ret, check.Equals, fs1)
	fs1.Parse(true, []string{"-x", "-y"})
	c.Assert(x, check.Equals, true)
	c.Assert(y, check.Equals, true)
}
开发者ID:vijaykanthm28,项目名称:libgo,代码行数:12,代码来源:utils_test.go

示例2: Run

func (c *helpCommand) Run(ctx *Context) error {
	// If there is no help topic specified, print basic usage.
	if c.topic == "" {
		if _, ok := c.topics["basics"]; ok {
			c.topic = "basics"
		} else {
			// At this point, "help" is selected as the SuperCommand's
			// sub-command, but we want the info to be printed
			// as if there was nothing selected.
			c.super.subcmd = nil

			info := c.super.Info()
			f := gnuflag.NewFlagSet(info.Name, gnuflag.ContinueOnError)
			c.SetFlags(f)
			ctx.Stdout.Write(info.Help(f))
			return nil
		}
	}
	// If the topic is a registered subcommand, then run the help command with it
	if helpcmd, ok := c.super.subcmds[c.topic]; ok {
		info := helpcmd.Info()
		info.Name = fmt.Sprintf("%s %s", c.super.Name, info.Name)
		f := gnuflag.NewFlagSet(info.Name, gnuflag.ContinueOnError)
		helpcmd.SetFlags(f)
		ctx.Stdout.Write(info.Help(f))
		return nil
	}
	// Look to see if the topic is a registered topic.
	topic, ok := c.topics[c.topic]
	if ok {
		fmt.Fprintf(ctx.Stdout, "%s\n", strings.TrimSpace(topic.long()))
		return nil
	}
	// If we have a missing callback, call that with --help
	if c.super.missingCallback != nil {
		subcmd := &missingCommand{
			callback:  c.super.missingCallback,
			superName: c.super.Name,
			name:      c.topic,
			args:      []string{"--", "--help"},
		}
		err := subcmd.Run(ctx)
		_, isUnrecognized := err.(*UnrecognizedCommand)
		if !isUnrecognized {
			return err
		}
	}
	return fmt.Errorf("unknown command or topic for %s", c.topic)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:49,代码来源:supercommand.go

示例3: Flags

func (c *rebalanceContainersCmd) Flags() *gnuflag.FlagSet {
	if c.fs == nil {
		c.fs = gnuflag.NewFlagSet("containers-rebalance", gnuflag.ExitOnError)
		c.fs.BoolVar(&c.dry, "dry", false, "Dry run, only shows what would be done")
	}
	return c.fs
}
开发者ID:renanoliveira,项目名称:tsuru,代码行数:7,代码来源:admin.go

示例4: Flags

func (c *CreateBridge) Flags() *gnuflag.FlagSet {
	if c.Fs == nil {
		c.Fs = gnuflag.NewFlagSet("megdc", gnuflag.ExitOnError)
		bridgeMsg := "specify the name of bridge"
		c.Fs.StringVar(&c.Bridgename, "bridgename", "one", bridgeMsg)
		phydevMsg := "specify the interfacename"
		c.Fs.StringVar(&c.PhyDev, "phydev", "eth0", phydevMsg)
		networkMsg := "specify the network address"
		c.Fs.StringVar(&c.Network, "network", "", networkMsg)
		netmaskMsg := "specify the netmask address"
		c.Fs.StringVar(&c.Netmask, "netmask", "", netmaskMsg)
		gatewayMsg := "specify the gateway address"
		c.Fs.StringVar(&c.Gateway, "gateway", "", gatewayMsg)
		dnsname1Msg := "specify the name server"
		c.Fs.StringVar(&c.Dnsname1, "dnsname1", "", dnsname1Msg)
		dnsname2Msg := "specify the name server"
		c.Fs.StringVar(&c.Dnsname2, "dnsname2", "", dnsname2Msg)
		hostMsg := "The host of the server to ssh"
		c.Fs.StringVar(&c.Host, "host", "localhost", hostMsg)
		usrMsg := "The username of the server"
		c.Fs.StringVar(&c.Username, "username", "", usrMsg)
		pwdMsg := "The password of the server"
		c.Fs.StringVar(&c.Password, "password", "", pwdMsg)
	}

	return c.Fs
}
开发者ID:ranjithamca,项目名称:megdc,代码行数:27,代码来源:createbridge.go

示例5: fs

func fs() (*gnuflag.FlagSet, *cmd.FileVar) {
	var config cmd.FileVar
	fs := gnuflag.NewFlagSet("", gnuflag.ContinueOnError)
	fs.SetOutput(ioutil.Discard)
	fs.Var(&config, "config", "the config")
	return fs, &config
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:7,代码来源:filevar_test.go

示例6: Flags

func (c *CreateNetworkOpennebula) Flags() *gnuflag.FlagSet {
	if c.Fs == nil {
		c.Fs = gnuflag.NewFlagSet("megdc", gnuflag.ExitOnError)
		bridgeMsg := " To specify physical bridge  in the host where the vm should connect this network interface."
		c.Fs.StringVar(&c.Bridge, "bridge", "one", bridgeMsg)
		iptypeMsg := "To specify ip address ip4 or ip6"
		c.Fs.StringVar(&c.Iptype, "iptype", "IP4", iptypeMsg)
		ipMsg := "To specify the ip"
		c.Fs.StringVar(&c.Ip, "ip", "", ipMsg)
		sizeMsg := "To specify range of ip address."
		c.Fs.StringVar(&c.Size, "size", "", sizeMsg)
		dns1Msg := "To specify domain server address"
		c.Fs.StringVar(&c.Dns1, "dns1", "", dns1Msg)
		dns2Msg := "To specify domain server address"
		c.Fs.StringVar(&c.Dns2, "dns2", "", dns2Msg)
		gatewayMsg := "To specify gateway address"
		c.Fs.StringVar(&c.Gatewayip, "gateway", "", gatewayMsg)
		netmaskMsg := "To specify netmask address"
		c.Fs.StringVar(&c.Networkmask, "networkmask", "", netmaskMsg)
		hostMsg := "To set the hostname"
		c.Fs.StringVar(&c.Host, "host", "localhost", hostMsg)
		usrMsg := "The username of the server"
		c.Fs.StringVar(&c.Username, "username", "", usrMsg)
		pwdMsg := "The password of the server"
		c.Fs.StringVar(&c.Password, "password", "", pwdMsg)
	}

	return c.Fs
}
开发者ID:ranjithamca,项目名称:megdc,代码行数:29,代码来源:network.go

示例7: Flags

func (c *Cephinstall) Flags() *gnuflag.FlagSet {
	if c.Fs == nil {
		c.Fs = gnuflag.NewFlagSet("megdc", gnuflag.ExitOnError)

		/* Install package commands */
		c.Fs.BoolVar(&c.CephInstall, "ceph", false, "Install ceph package")
		c.Fs.BoolVar(&c.CephInstall, "c", false, "Install ceph package")

		c.Fs.StringVar(&c.CEPH_LOG, "ceph_log", "", "ceph_log path for hosted machine")
		c.Fs.StringVar(&c.CEPH_LOG, "l", "", "ceph_log path for hosted machine")
		c.Fs.StringVar(&c.Ceph_user, "ceph_user", "", "ceph_user for hosted machine")
		c.Fs.StringVar(&c.Ceph_user, "u", "", "ceph_user for hosted machine")
		c.Fs.StringVar(&c.Ceph_password, "ceph_password", "", "ceph_password for hosted machine")
		c.Fs.StringVar(&c.Ceph_password, "p", "", "ceph_password for hosted machine")
		c.Fs.StringVar(&c.Ceph_group, "ceph_group", "", "ceph_group for hosted machine")
		c.Fs.StringVar(&c.Ceph_group, "g", "", "ceph_group for hosted machine")
		c.Fs.StringVar(&c.User_home, "user_home", "", "user_home path for hosted machine")
		c.Fs.StringVar(&c.User_home, "uh", "", "user_home path for hosted machine")
		c.Fs.StringVar(&c.Host, "host", "", "host address for machine")
		c.Fs.StringVar(&c.Host, "h", "", "host address for machine")
		c.Fs.StringVar(&c.Osd1, "osd1", "", "osd1 storage drive for hosted machine")
		c.Fs.StringVar(&c.Osd1, "os1", "", "osd1 strorage drive for hosted machine")
		c.Fs.StringVar(&c.Osd2, "osd2", "", "osd2 storage drive for hosted machine")
		c.Fs.StringVar(&c.Osd2, "os2", "", "osd2 strorage drive for hosted machine")
		c.Fs.StringVar(&c.Osd3, "osd3", "", "osd3 storage drive for hosted machine")
		c.Fs.StringVar(&c.Osd3, "os3", "", "osd3 strorage drive for hosted machine")

		c.Fs.BoolVar(&c.Quiet, "quiet", false, "")
		c.Fs.BoolVar(&c.Quiet, "q", false, "")
	}
	return c.Fs
}
开发者ID:mehulsbhatt,项目名称:megdc,代码行数:32,代码来源:cephinstall.go

示例8: TestNewContext

func (*suite) TestNewContext(c *gc.C) {
	for i, test := range newContextTests {
		c.Logf("test %d: %s", i, test.about)
		fset := flag.NewFlagSet("http", flag.ContinueOnError)
		ctxt, _, err := newContext(fset, test.args)
		if test.expectError != "" {
			c.Assert(err, gc.ErrorMatches, test.expectError)
			continue
		}
		c.Assert(err, gc.IsNil)
		if len(ctxt.header) == 0 {
			ctxt.header = nil
		}
		if len(ctxt.urlValues) == 0 {
			ctxt.urlValues = nil
		}
		if len(ctxt.form) == 0 {
			ctxt.form = nil
		}
		if len(ctxt.jsonObj) == 0 {
			ctxt.jsonObj = nil
		}
		c.Logf("url %s", ctxt.url)
		c.Assert(ctxt, jc.DeepEquals, &test.expectContext)
	}
}
开发者ID:nathj07,项目名称:http,代码行数:26,代码来源:http_test.go

示例9: Flags

func (a *updateNodeToSchedulerCmd) Flags() *gnuflag.FlagSet {
	if a.fs == nil {
		a.fs = gnuflag.NewFlagSet("", gnuflag.ExitOnError)
		a.fs.BoolVar(&a.disabled, "disable", false, "Disable node in scheduler.")
	}
	return a.fs
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:7,代码来源:cmd.go

示例10: main

func main() {
	fset := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
	ctxt, p, err := newContext(fset, os.Args[1:])
	if err != nil {
		if err == errUsage {
			fset.Usage()
		} else {
			fmt.Fprintf(os.Stderr, "%v\n", err)
		}
		os.Exit(2)
	}
	jar, client, err := newClient(p)
	if err != nil {
		fatalf("cannot make HTTP client: %v", err)
	}
	if jar != nil {
		defer jar.Save()
	}
	var stdin io.Reader
	if p.useStdin {
		stdin = os.Stdin
	}
	resp, err := ctxt.doRequest(client, stdin)
	if err != nil {
		fatalf("%v", err)
	}
	defer resp.Body.Close()
	if err := showResponse(p, resp, os.Stdout); err != nil {
		fatalf("%v", err)
	}
}
开发者ID:nathj07,项目名称:http,代码行数:31,代码来源:http.go

示例11: Flags

func (c *VerticeInstall) Flags() *gnuflag.FlagSet {
	if c.Fs == nil {
		c.Fs = gnuflag.NewFlagSet("", gnuflag.ExitOnError)
		nilMsg := "Install megam cockpit ui"
		c.Fs.BoolVar(&c.NilavuInstall, "nilavu", false, nilMsg)
		c.Fs.BoolVar(&c.NilavuInstall, "n", false, nilMsg)
		gwyMsg := "Install megam gateway apiserver"
		c.Fs.BoolVar(&c.GatewayInstall, "gateway", false, gwyMsg)
		c.Fs.BoolVar(&c.GatewayInstall, "g", false, gwyMsg)
		snoMsg := "Install megam uidserver"
		c.Fs.BoolVar(&c.SnowflakeInstall, "snowflake", false, snoMsg)
		c.Fs.BoolVar(&c.SnowflakeInstall, "s", false, snoMsg)
		megdMsg := "Install megam omni scheduler"
		c.Fs.BoolVar(&c.MegamdInstall, "vertice", false, megdMsg)
		c.Fs.BoolVar(&c.MegamdInstall, "d", false, megdMsg)
		hostMsg := "The host of the server to ssh"
		c.Fs.StringVar(&c.Host, "host", "localhost", hostMsg)
		usrMsg := "The username of the server"
		c.Fs.StringVar(&c.Username, "username", "", usrMsg)
		pwdMsg := "The password of the server"
		c.Fs.StringVar(&c.Password, "password", "", pwdMsg)
	}
	//	c.Fs = cmd.MergeFlagSet(new(packages.SSHCommand).Flags(), c.Fs)
	return c.Fs
}
开发者ID:rajthilakmca,项目名称:megdc,代码行数:25,代码来源:verticeinstall.go

示例12: RunPlugin

func RunPlugin(ctx *cmd.Context, subcommand string, args []string) error {
	cmdName := JujuPluginPrefix + subcommand
	plugin := modelcmd.Wrap(&PluginCommand{name: cmdName})

	// We process common flags supported by Juju commands.
	// To do this, we extract only those supported flags from the
	// argument list to avoid confusing flags.Parse().
	flags := gnuflag.NewFlagSet(cmdName, gnuflag.ContinueOnError)
	flags.SetOutput(ioutil.Discard)
	plugin.SetFlags(flags)
	jujuArgs := extractJujuArgs(args)
	if err := flags.Parse(false, jujuArgs); err != nil {
		return err
	}
	if err := plugin.Init(args); err != nil {
		return err
	}
	err := plugin.Run(ctx)
	_, execError := err.(*exec.Error)
	// exec.Error results are for when the executable isn't found, in
	// those cases, drop through.
	if !execError {
		return err
	}
	return &cmd.UnrecognizedCommand{Name: subcommand}
}
开发者ID:exekias,项目名称:juju,代码行数:26,代码来源:plugin.go

示例13: Flags

func (f *fakeCommand) Flags() *gnuflag.FlagSet {
	if f.fs == nil {
		f.fs = gnuflag.NewFlagSet("fakeCommand", gnuflag.ExitOnError)
		f.fs.StringVar(&f.name, "name", "", "your name")
	}
	return f.fs
}
开发者ID:ningjh,项目名称:tsuru,代码行数:7,代码来源:command_test.go

示例14: Flags

func (c *Megamremove) Flags() *gnuflag.FlagSet {
	if c.Fs == nil {
		c.Fs = gnuflag.NewFlagSet("megdc", gnuflag.ExitOnError)
		c.Fs.BoolVar(&c.All, "all", false, "Remove all megam packages")
		c.Fs.BoolVar(&c.All, "a", false, "Remove all megam packages")

		/* Remove package commands */
		c.Fs.BoolVar(&c.MegamNilavuRemove, "megamnilavu", false, "Remove nilavu package")
		c.Fs.BoolVar(&c.MegamNilavuRemove, "n", false, "Remove nilavu package")
		c.Fs.BoolVar(&c.MegamGatewayRemove, "megamgateway", false, "Remove megam gateway package")
		c.Fs.BoolVar(&c.MegamGatewayRemove, "g", false, "Remove megam gateway package")
		c.Fs.BoolVar(&c.MegamdRemove, "megamd", false, "Remove megamd package")
		c.Fs.BoolVar(&c.MegamdRemove, "d", false, "Remove megamd package")
		c.Fs.BoolVar(&c.MegamCommonRemove, "megamcommon", false, "Remove megamcommon package")
		c.Fs.BoolVar(&c.MegamCommonRemove, "c", false, "Remove megamcommon package")
		c.Fs.BoolVar(&c.MegamSnowflakeRemove, "megamsnowflake", false, "Remove megam snowflake package")
		c.Fs.BoolVar(&c.MegamSnowflakeRemove, "s", false, "Remove megam snowflake package")
		c.Fs.BoolVar(&c.RiakRemove, "riak", false, "Remove Riak package")
		c.Fs.BoolVar(&c.RiakRemove, "r", false, "Remove Riak package")
		c.Fs.BoolVar(&c.RabbitmqRemove, "rabbitmq", false, "Remove Rabbitmq-server")
		c.Fs.BoolVar(&c.RabbitmqRemove, "m", false, "Remove Rabbitmq-server")

		c.Fs.StringVar(&c.Host, "host", "", "host address for machine")
		c.Fs.StringVar(&c.Host, "h", "", "host address for machine")
		c.Fs.StringVar(&c.Username, "username", "", "username for hosted machine")
		c.Fs.StringVar(&c.Username, "u", "", "username for hosted machine")
		c.Fs.StringVar(&c.Password, "password", "", "password for hosted machine")
		c.Fs.StringVar(&c.Password, "p", "", "password for hosted machine")
		c.Fs.BoolVar(&c.Quiet, "quiet", false, "")
		c.Fs.BoolVar(&c.Quiet, "q", false, "")
	}
	return c.Fs
}
开发者ID:mehulsbhatt,项目名称:megdc,代码行数:33,代码来源:megamremove.go

示例15: 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


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