本文整理汇总了Golang中github.com/docker/docker/pkg/mflag.NewFlagSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFlagSet函数的具体用法?Golang NewFlagSet怎么用?Golang NewFlagSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFlagSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestFindConfigurationConflictsWithMergedValues
func TestFindConfigurationConflictsWithMergedValues(t *testing.T) {
var hosts []string
config := map[string]interface{}{"hosts": "tcp://127.0.0.1:2345"}
base := mflag.NewFlagSet("base", mflag.ContinueOnError)
base.Var(opts.NewNamedListOptsRef("hosts", &hosts, nil), []string{"H", "-host"}, "")
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
mflag.Merge(flags, base)
err := findConfigurationConflicts(config, flags)
if err != nil {
t.Fatal(err)
}
flags.Set("-host", "unix:///var/run/docker.sock")
err = findConfigurationConflicts(config, flags)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "hosts: (from flag: [unix:///var/run/docker.sock], from file: tcp://127.0.0.1:2345)") {
t.Fatalf("expected hosts conflict, got %v", err)
}
}
开发者ID:CrocdileChan,项目名称:docker,代码行数:23,代码来源:config_test.go
示例17: TestLoadDaemonCliConfigWithDaemonFlags
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
c := &daemon.Config{}
common := &cli.CommonFlags{
Debug: true,
LogLevel: "info",
}
f, err := ioutil.TempFile("", "docker-config-")
if err != nil {
t.Fatal(err)
}
configFile := f.Name()
f.Write([]byte(`{"log-opts": {"max-size": "1k"}}`))
f.Close()
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
flags.String([]string{daemonConfigFileFlag}, "", "")
flags.BoolVar(&c.EnableSelinuxSupport, []string{"-selinux-enabled"}, true, "")
flags.StringVar(&c.LogConfig.Type, []string{"-log-driver"}, "json-file", "")
flags.Var(opts.NewNamedMapOpts("log-opts", c.LogConfig.Config, nil), []string{"-log-opt"}, "")
flags.Set(daemonConfigFileFlag, configFile)
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.Debug {
t.Fatalf("expected debug mode, got false")
}
if loadedConfig.LogLevel != "info" {
t.Fatalf("expected info log level, got %v", loadedConfig.LogLevel)
}
if !loadedConfig.EnableSelinuxSupport {
t.Fatalf("expected enabled selinux support, got disabled")
}
if loadedConfig.LogConfig.Type != "json-file" {
t.Fatalf("expected LogConfig type json-file, got %v", loadedConfig.LogConfig.Type)
}
if maxSize := loadedConfig.LogConfig.Config["max-size"]; maxSize != "1k" {
t.Fatalf("expected log max-size `1k`, got %s", maxSize)
}
}
开发者ID:ailispaw,项目名称:docker,代码行数:46,代码来源:daemon_unix_test.go
示例18: TestFindConfigurationConflicts
func TestFindConfigurationConflicts(t *testing.T) {
config := map[string]interface{}{"authorization-plugins": "foobar"}
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
flags.String([]string{"-authorization-plugins"}, "", "")
if err := flags.Set("-authorization-plugins", "asdf"); err != nil {
t.Fatal(err)
}
err := findConfigurationConflicts(config, flags)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "authorization-plugins: (from flag: asdf, from file: foobar)") {
t.Fatalf("expected authorization-plugins conflict, got %v", err)
}
}
开发者ID:CrocdileChan,项目名称:docker,代码行数:17,代码来源:config_test.go
示例19: Subcmd
// Subcmd is a subcommand of the main "docker" command.
// A subcommand represents an action that can be performed
// from the Docker command line client.
//
// Multiple subcommand synopses may be provided with one 'Usage' line being
// printed for each in the following way:
//
// Usage: docker <subcmd-name> [OPTIONS] <synopsis 0>
// docker <subcmd-name> [OPTIONS] <synopsis 1>
// ...
//
// If no undeprecated flags are added to the returned FlagSet, "[OPTIONS]" will
// not be included on the usage synopsis lines. If no synopses are given, only
// one usage synopsis line will be printed with nothing following the
// "[OPTIONS]" section
//
// To see all available subcommands, run "docker --help".
func (cli *DockerCli) Subcmd(name string, synopses []string, 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 flags.FlagCountUndeprecated() > 0 {
options = " [OPTIONS]"
}
if len(synopses) == 0 {
synopses = []string{""}
}
// Allow for multiple command usage synopses.
for i, synopsis := range synopses {
lead := "\t"
if i == 0 {
// First line needs the word 'Usage'.
lead = "Usage:\t"
}
if synopsis != "" {
synopsis = " " + synopsis
}
fmt.Fprintf(flags.Out(), "\n%sdocker %s%s%s", lead, name, options, synopsis)
}
fmt.Fprintf(flags.Out(), "\n\n%s\n", description)
}
return flags
}
开发者ID:fengbaicanhe,项目名称:docker,代码行数:62,代码来源:cli.go
示例20: initDaemon
func initDaemon(c *cli.Context) (*daemon.Daemon, *graph.TagStore, *graph.Graph, graphdriver.Driver) {
t, tc, g, d := initTagStoreAndConfig(c)
config := &daemon.Config{}
config.DisableBridge = true
config.GraphDriver = c.GlobalString("driver")
config.GraphOptions = c.GlobalStringSlice("storage-opt")
home := c.GlobalString("home")
config.Root = home
config.TrustKeyPath = filepath.Join(c.GlobalString("configdir"), "key.json")
flags := mflag.NewFlagSet("graphc", mflag.ExitOnError)
config.InstallFlags(flags, func(string) string { return "" })
daemon, err := daemon.NewDaemon(config, tc.Registry)
if err != nil {
fmt.Printf("Failed to instantiate daemon: %s\n", err)
os.Exit(1)
}
return daemon, t, g, d
}
开发者ID:nalind,项目名称:graphc,代码行数:18,代码来源:graphc.go
注:本文中的github.com/docker/docker/pkg/mflag.NewFlagSet函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论