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


Golang mflag.NewFlagSet函数代码示例

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


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

示例1: TestLoadDaemonCliConfigWithConflicts

func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}
	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"labels": ["l3=foo"]}`))
	f.Close()

	var labels []string

	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.String([]string{daemonConfigFileFlag}, "", "")
	flags.Var(opts.NewNamedListOptsRef("labels", &labels, opts.ValidateLabel), []string{"-label"}, "")

	flags.Set(daemonConfigFileFlag, configFile)
	if err := flags.Set("-label", "l1=bar"); err != nil {
		t.Fatal(err)
	}
	if err := flags.Set("-label", "l2=baz"); err != nil {
		t.Fatal(err)
	}

	_, err = loadDaemonCliConfig(c, flags, common, configFile)
	if err == nil {
		t.Fatalf("expected configuration error, got nil")
	}
	if !strings.Contains(err.Error(), "labels") {
		t.Fatalf("expected labels conflict, got %v", err)
	}
}
开发者ID:supasate,项目名称:docker,代码行数:34,代码来源:daemon_test.go

示例2: TestLoadDaemonConfigWithEmbeddedOptions

func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.String([]string{"-tlscacert"}, "", "")
	flags.String([]string{"-log-driver"}, "", "")

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"tlscacert": "/etc/certs/ca.pem", "log-driver": "syslog"}`))
	f.Close()

	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatal("expected configuration, got nil")
	}
	if loadedConfig.CommonTLSOptions.CAFile != "/etc/certs/ca.pem" {
		t.Fatalf("expected CA file path /etc/certs/ca.pem, got %v", loadedConfig.CommonTLSOptions.CAFile)
	}
	if loadedConfig.LogConfig.Type != "syslog" {
		t.Fatalf("expected LogConfig type syslog, got %v", loadedConfig.LogConfig.Type)
	}
}
开发者ID:supasate,项目名称:docker,代码行数:30,代码来源:daemon_test.go

示例3: TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults

func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	if err := flags.ParseFlags([]string{}, false); err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{}`))
	f.Close()

	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatal("expected configuration, got nil")
	}

	if !loadedConfig.EnableUserlandProxy {
		t.Fatal("expected userland proxy to be enabled, got disabled")
	}
}
开发者ID:contiv,项目名称:docker,代码行数:31,代码来源:daemon_unix_test.go

示例4: TestLoadDaemonCliConfigWithLogLevel

func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"log-level": "warn"}`))
	f.Close()

	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.String([]string{"-log-level"}, "", "")
	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatalf("expected configuration %v, got nil", c)
	}
	if loadedConfig.LogLevel != "warn" {
		t.Fatalf("expected warn log level, got %v", loadedConfig.LogLevel)
	}

	if logrus.GetLevel() != logrus.WarnLevel {
		t.Fatalf("expected warn log level, got %v", logrus.GetLevel())
	}
}
开发者ID:supasate,项目名称:docker,代码行数:30,代码来源:daemon_test.go

示例5: prepare

func prepare(args []string) (dockerOpt *docker.CreateContainerOptions, removeOnExit bool, eqCfg config.Config, err error) {
	if len(args) < 3 {
		// FIXME
		err = fmt.Errorf("bad argument: %s", args)
		return
	}
	flagSet := flag.NewFlagSet("run", flag.ExitOnError)
	dockerOpt, err = parseRun(flagSet, args[1:])
	if err != nil {
		return
	}
	removeOnExit = flagSet.IsSet("-rm")

	eqCfgPath := flagSet.Lookup("-eq-config").Value.String()
	eqCfg, err = newConfig(eqCfgPath)
	if err != nil {
		err = fmt.Errorf("bad config: %s", err)
		return
	}
	log.Debugf("Earthquake Config=%s", eqCfg)

	if err = checkPrerequisite(eqCfg); err != nil {
		err = fmt.Errorf("prerequisite error: %s", err)
	}
	return
}
开发者ID:terminiter,项目名称:earthquake,代码行数:26,代码来源:run.go

示例6: rewriteTLSFlags

func rewriteTLSFlags(dcli *DockerfCli, machine string, cluster string) {
	if machine == "" {
		return
	}
	tlsFlagArgs := func(machineName string) []string {
		mp := dmachine.NewMachineProxy("container-tls-config")
		if flags, err := mp.Config(machineName, cluster); err != nil {
			fmt.Printf("Load Machine(name:%s, cluster:%s) configs error:%s\n", machine, cluster, err.Error())
			return []string{}
		} else {
			return strings.Split(flags, " ")
		}
	}(machine)

	tlsFlagset := flag.NewFlagSet("tls-docker-machine", flag.ExitOnError)

	flTls = tlsFlagset.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify")
	flTlsVerify = tlsFlagset.Bool([]string{"-tlsverify"}, false, "Use TLS and verify the remote")
	flCa = tlsFlagset.String([]string{"-tlscacert"}, "", "Trust certs signed only by this CA")
	flCert = tlsFlagset.String([]string{"-tlscert"}, "", "Path to TLS certificate file")
	flKey = tlsFlagset.String([]string{"-tlskey"}, "", "Path to TLS key file")

	listOpts := opts.NewListOpts(nil)
	tlsFlagset.Var(&listOpts, []string{"H", "-host"}, "Daemon socket(s) to connect to")

	tlsFlagset.Parse(tlsFlagArgs)

	flHosts = listOpts.GetAll()

}
开发者ID:jiangshengwu,项目名称:dockerf,代码行数:30,代码来源:cmd_container.go

示例7: TestLoadDaemonConfigWithLegacyRegistryOptions

func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
	c := &daemon.Config{}
	common := &cliflags.CommonFlags{}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}
	configFile := f.Name()
	defer os.Remove(configFile)

	f.Write([]byte(`{"disable-legacy-registry": true}`))
	f.Close()

	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatal("expected configuration, got nil")
	}

	if !loadedConfig.V2Only {
		t.Fatal("expected disable-legacy-registry to be true, got false")
	}
}
开发者ID:rlugojr,项目名称:docker,代码行数:28,代码来源:daemon_unix_test.go

示例8: TestLoadDaemonConfigWithNetwork

func TestLoadDaemonConfigWithNetwork(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.String([]string{"-bip"}, "", "")
	flags.String([]string{"-ip"}, "", "")

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"bip": "127.0.0.2", "ip": "127.0.0.1"}`))
	f.Close()

	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatalf("expected configuration %v, got nil", c)
	}
	if loadedConfig.IP != "127.0.0.2" {
		t.Fatalf("expected IP 127.0.0.2, got %v", loadedConfig.IP)
	}
	if loadedConfig.DefaultIP.String() != "127.0.0.1" {
		t.Fatalf("expected DefaultIP 127.0.0.1, got %s", loadedConfig.DefaultIP)
	}
}
开发者ID:contiv,项目名称:docker,代码行数:30,代码来源:daemon_unix_test.go

示例9: Subcmd

// Subcmd is borrowed from Docker UI and performs the same function of configuring the subCmds
func (cli *NetworkCli) Subcmd(chain, name, signature, description string, exitOnError bool) *flag.FlagSet {
	var errorHandling flag.ErrorHandling
	if exitOnError {
		errorHandling = flag.ExitOnError
	} else {
		errorHandling = flag.ContinueOnError
	}
	flags := flag.NewFlagSet(name, errorHandling)
	flags.Usage = func() {
		flags.ShortUsage()
		flags.PrintDefaults()
	}
	flags.ShortUsage = func() {
		options := ""
		if signature != "" {
			signature = " " + signature
		}
		if flags.FlagCountUndeprecated() > 0 {
			options = " [OPTIONS]"
		}
		fmt.Fprintf(cli.out, "\nUsage: %s %s%s%s\n\n%s\n\n", chain, name, options, signature, description)
		flags.SetOutput(cli.out)
	}
	return flags
}
开发者ID:winsx,项目名称:libnetwork,代码行数:26,代码来源:client.go

示例10: TestLoadDaemonCliConfigWithTLSVerify

func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{
		TLSOptions: &tlsconfig.Options{
			CAFile: "/tmp/ca.pem",
		},
	}

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"tlsverify": true}`))
	f.Close()

	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.Bool([]string{"-tlsverify"}, false, "")
	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatalf("expected configuration %v, got nil", c)
	}

	if !loadedConfig.TLS {
		t.Fatalf("expected TLS enabled, got %q", loadedConfig)
	}
}
开发者ID:supasate,项目名称:docker,代码行数:31,代码来源:daemon_test.go

示例11: TestLoadDaemonConfigWithRegistryOptions

func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
	c := &daemon.Config{}
	common := &cliflags.CommonFlags{}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}
	configFile := f.Name()
	defer os.Remove(configFile)

	f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"]}`))
	f.Close()

	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatal("expected configuration, got nil")
	}

	m := loadedConfig.Mirrors
	if len(m) != 1 {
		t.Fatalf("expected 1 mirror, got %d", len(m))
	}

	r := loadedConfig.InsecureRegistries
	if len(r) != 1 {
		t.Fatalf("expected 1 insecure registries, got %d", len(r))
	}
}
开发者ID:rlugojr,项目名称:docker,代码行数:34,代码来源:daemon_test.go

示例12: Subcmd

func (cli *DockerCli) Subcmd(name, signature, description string) *flag.FlagSet {
	flags := flag.NewFlagSet(name, flag.ContinueOnError)
	flags.Usage = func() {
		fmt.Fprintf(cli.err, "\nUsage: docker %s %s\n\n%s\n\n", name, signature, description)
		flags.PrintDefaults()
		os.Exit(2)
	}
	return flags
}
开发者ID:bb4242,项目名称:systemd-docker,代码行数:9,代码来源:cli.go

示例13: run

// RUN some command yo
//
// run a command and commit the image. Args are automatically prepended with
// 'sh -c' in the event there is only one argument. The difference in
// processing:
//
// RUN echo hi          # sh -c echo hi
// RUN [ "echo", "hi" ] # echo hi
//
func run(b *Builder, args []string, attributes map[string]bool, original string) error {
	if b.image == "" && !b.noBaseImage {
		return fmt.Errorf("Please provide a source image with `from` prior to run")
	}

	args = handleJsonArgs(args, attributes)

	if !attributes["json"] {
		args = append([]string{"/bin/sh", "-c"}, args...)
	}

	runCmd := flag.NewFlagSet("run", flag.ContinueOnError)
	runCmd.SetOutput(ioutil.Discard)
	runCmd.Usage = nil

	config, _, _, err := runconfig.Parse(runCmd, append([]string{b.image}, args...))
	if err != nil {
		return err
	}

	cmd := b.Config.Cmd
	// set Cmd manually, this is special case only for Dockerfiles
	b.Config.Cmd = config.Cmd
	runconfig.Merge(b.Config, config)

	defer func(cmd []string) { b.Config.Cmd = cmd }(cmd)

	logrus.Debugf("[BUILDER] Command to be executed: %v", b.Config.Cmd)

	hit, err := b.probeCache()
	if err != nil {
		return err
	}
	if hit {
		return nil
	}

	c, err := b.create()
	if err != nil {
		return err
	}

	// Ensure that we keep the container mounted until the commit
	// to avoid unmounting and then mounting directly again
	c.Mount()
	defer c.Unmount()

	err = b.run(c)
	if err != nil {
		return err
	}
	if err := b.commit(c.ID, cmd, "run"); err != nil {
		return err
	}

	return nil
}
开发者ID:jbbarth,项目名称:docker,代码行数:66,代码来源:dispatchers.go

示例14: Subcmd

func (cli *DockerCli) Subcmd(name, signature, description string) *flag.FlagSet {
	flags := flag.NewFlagSet(name, flag.ContinueOnError)
	flags.Usage = func() {
		options := ""
		if flags.FlagCountUndeprecated() > 0 {
			options = "[OPTIONS] "
		}
		fmt.Fprintf(cli.err, "\nUsage: docker %s %s%s\n\n%s\n\n", name, options, signature, description)
		flags.PrintDefaults()
		os.Exit(2)
	}
	return flags
}
开发者ID:BreezeWu,项目名称:docker,代码行数:13,代码来源:cli.go

示例15: TestFindConfigurationConflictsWithUnknownKeys

func TestFindConfigurationConflictsWithUnknownKeys(t *testing.T) {
	config := map[string]interface{}{"tls-verify": "true"}
	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)

	flags.Bool([]string{"-tlsverify"}, false, "")
	err := findConfigurationConflicts(config, flags)
	if err == nil {
		t.Fatal("expected error, got nil")
	}
	if !strings.Contains(err.Error(), "the following directives don't match any configuration option: tls-verify") {
		t.Fatalf("expected tls-verify conflict, got %v", err)
	}
}
开发者ID:CrocdileChan,项目名称:docker,代码行数:13,代码来源:config_test.go


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