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


Golang pflag.NormalizedName函数代码示例

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


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

示例1: WarnWordSepNormalizeFunc

// WarnWordSepNormalizeFunc changes and warns for flags that contain "_" separators
func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
	if strings.Contains(name, "_") {
		nname := strings.Replace(name, "_", "-", -1)
		glog.Warningf("%s is DEPRECATED and will be removed in a future version. Use %s instead.", name, nname)

		return pflag.NormalizedName(nname)
	}
	return pflag.NormalizedName(name)
}
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:10,代码来源:flags.go

示例2: main

func main() {
	// configuration
	cfg := pkg.NewConfig()

	// flags
	fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	fs.StringVar(&cfg.IngressesData, "ingresses-data", cfg.IngressesData, "Ingresses data.")
	fs.StringVar(&cfg.KubeMasterURL, "kube-master-url", cfg.KubeMasterURL, "URL to reach kubernetes master.")
	fs.StringVar(&cfg.Namespace, "namespace", cfg.Namespace, "If present, the namespace scope.")
	fs.StringVar(&cfg.Selector, "selector", cfg.Selector, "Filter resources by a user-provided selector.")
	fs.DurationVar(&cfg.ResyncInterval, "resync-interval", cfg.ResyncInterval, "Resync with kubernetes master every user-defined interval.")
	fs.StringVar(&cfg.NginxSrc, "nginx-src", cfg.NginxSrc, "nginx.conf template file path.")
	fs.StringVar(&cfg.NginxDest, "nginx-dst", cfg.NginxDest, "nginx.conf destination file path.")
	fs.IntVar(&cfg.NginxDestUid, "nginx-dst-uid", cfg.NginxDestUid, "nginx.conf destination file uid.")
	fs.IntVar(&cfg.NginxDestGid, "nginx-dst-gid", cfg.NginxDestGid, "nginx.conf destination file gid.")
	fs.StringVar(&cfg.NginxDestMode, "nginx-dst-mode", cfg.NginxDestMode, "nginx.conf destination file mode.")
	fs.StringVar(&cfg.NginxCheckCmd, "nginx-check-cmd", cfg.NginxCheckCmd, "nginx check command.")
	fs.StringVar(&cfg.NginxReloadCmd, "nginx-reload-cmd", cfg.NginxReloadCmd, "nginx reload command.")
	fs.SetNormalizeFunc(
		func(f *flag.FlagSet, name string) flag.NormalizedName {
			if strings.Contains(name, "_") {
				return flag.NormalizedName(strings.Replace(name, "_", "-", -1))
			}
			return flag.NormalizedName(name)
		},
	)

	// parse
	fs.Parse(os.Args[1:])

	// set from env (if present)
	fs.VisitAll(func(f *flag.Flag) {
		if !f.Changed {
			key := strings.ToUpper(strings.Join(
				[]string{
					cliName,
					strings.Replace(f.Name, "-", "_", -1),
				},
				"_",
			))
			val := os.Getenv(key)
			if val != "" {
				fs.Set(f.Name, val)
			}
		}
	})

	// and then, run!
	k2n := pkg.NewKubeToNginx(cfg)
	k2n.Run()
}
开发者ID:glerchundi,项目名称:kube2nginx,代码行数:51,代码来源:main.go

示例3: main

func main() {
	// configuration
	cfg := pkg.NewConfig()

	// flags
	fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	fs.StringVar(&cfg.Me, "me", cfg.Me, "me.")
	fs.StringVar(&cfg.Members, "members", cfg.Members, "members.")
	fs.StringVar(&cfg.TmplListenUrl, "tmpl-listen-url", cfg.TmplListenUrl, "tmpl-listen-url.")
	fs.StringVar(&cfg.TmplPeerUrl, "tmpl-peer-url", cfg.TmplPeerUrl, "tmpl-peer-url.")
	fs.StringVar(&cfg.CertFile, "cert-file", cfg.CertFile, "Identify HTTPS client using this SSL certificate file.")
	fs.StringVar(&cfg.KeyFile, "key-file", cfg.KeyFile, "Identify HTTPS client using this SSL key file.")
	fs.StringVar(&cfg.CAFile, "ca-file", cfg.CAFile, "Verify certificates of HTTPS-enabled servers using this CA bundle.")
	fs.BoolVar(&cfg.Force, "force", cfg.Force, "force.")
	fs.StringVar(&cfg.Out, "out", cfg.Out, "etcd2 peers environment file destination")
	fs.SetNormalizeFunc(
		func(f *flag.FlagSet, name string) flag.NormalizedName {
			if strings.Contains(name, "_") {
				return flag.NormalizedName(strings.Replace(name, "_", "-", -1))
			}
			return flag.NormalizedName(name)
		},
	)

	// parse
	fs.Parse(os.Args[1:])

	// set from env (if present)
	fs.VisitAll(func(f *flag.Flag) {
		if !f.Changed {
			key := strings.ToUpper(strings.Join(
				[]string{
					cliName,
					strings.Replace(f.Name, "-", "_", -1),
				},
				"_",
			))
			val := os.Getenv(key)
			if val != "" {
				fs.Set(f.Name, val)
			}
		}
	})

	// and then, run!
	eb := pkg.NewEtcd2Bootstrapper(cfg)
	eb.Run()
}
开发者ID:glerchundi,项目名称:etcd2-bootstrapper,代码行数:48,代码来源:main.go

示例4: main

func main() {
	// configuration
	cfg := pkg.NewConfig()

	// flags
	fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	fs.StringVar(&cfg.KubeMasterURL, "kube-master-url", cfg.KubeMasterURL, "URL to reach kubernetes master.")
	fs.StringVar(&cfg.Namespace, "namespace", cfg.Namespace, "If present, the namespace scope.")
	fs.StringVar(&cfg.Resource, "resource", cfg.Resource, "Which resource to watch.")
	fs.StringVar(&cfg.Selector, "selector", cfg.Selector, "Filter resources by a user-provided selector.")
	fs.DurationVar(&cfg.ResyncInterval, "resync-interval", cfg.ResyncInterval, "Resync with kubernetes master every user-defined interval.")
	fs.StringVar(&cfg.AddEventsFile, "add-events-file", cfg.AddEventsFile, "File in which the events of type 'add' are printed.")
	fs.StringVar(&cfg.UpdateEventsFile, "update-events-file", cfg.UpdateEventsFile, "File in which the events of type 'update' are printed.")
	fs.StringVar(&cfg.DeleteEventsFile, "delete-events-file", cfg.DeleteEventsFile, "File in which the events of type 'delete' are printed.")
	fs.SetNormalizeFunc(
		func(f *flag.FlagSet, name string) flag.NormalizedName {
			if strings.Contains(name, "_") {
				return flag.NormalizedName(strings.Replace(name, "_", "-", -1))
			}
			return flag.NormalizedName(name)
		},
	)

	// parse
	fs.Parse(os.Args[1:])

	// set from env (if present)
	fs.VisitAll(func(f *flag.Flag) {
		if !f.Changed {
			key := strings.ToUpper(strings.Join(
				[]string{
					cliName,
					strings.Replace(f.Name, "-", "_", -1),
				},
				"_",
			))
			val := os.Getenv(key)
			if val != "" {
				fs.Set(f.Name, val)
			}
		}
	})

	// and then, run!
	kl := pkg.NewKubeListener(cfg)
	kl.Run()
}
开发者ID:glerchundi,项目名称:kube2nginx,代码行数:47,代码来源:main.go

示例5: WordSepNormalizeFunc

func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
	from := []string{"-", "_"}
	to := "."
	for _, sep := range from {
		name = strings.Replace(name, sep, to, -1)
	}
	// Type convert to indicate normalization has been done.
	return pflag.NormalizedName(name)
}
开发者ID:cjnygard,项目名称:origin,代码行数:9,代码来源:flags.go

示例6: NormalizeHugoFlags

// NormalizeHugoFlags facilitates transitions of Hugo command-line flags,
// e.g. --baseUrl to --baseURL, --uglyUrls to --uglyURLs
func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
	switch name {
	case "baseUrl":
		name = "baseURL"
		break
	case "uglyUrls":
		name = "uglyURLs"
		break
	}
	return pflag.NormalizedName(name)
}
开发者ID:yanwushuang,项目名称:pango,代码行数:13,代码来源:general.go

示例7: TestGlobalNormFuncPropagation

func TestGlobalNormFuncPropagation(t *testing.T) {
	normFunc := func(f *pflag.FlagSet, name string) pflag.NormalizedName {
		return pflag.NormalizedName(name)
	}

	rootCmd := initialize()
	rootCmd.SetGlobalNormalizationFunc(normFunc)
	if reflect.ValueOf(normFunc) != reflect.ValueOf(rootCmd.GlobalNormalizationFunc()) {
		t.Error("rootCmd seems to have a wrong normalization function")
	}

	// First add the cmdEchoSub to cmdPrint
	cmdPrint.AddCommand(cmdEchoSub)
	if cmdPrint.GlobalNormalizationFunc() != nil && cmdEchoSub.GlobalNormalizationFunc() != nil {
		t.Error("cmdPrint and cmdEchoSub should had no normalization functions")
	}

	// Now add cmdPrint to rootCmd
	rootCmd.AddCommand(cmdPrint)
	if reflect.ValueOf(cmdPrint.GlobalNormalizationFunc()).Pointer() != reflect.ValueOf(rootCmd.GlobalNormalizationFunc()).Pointer() ||
		reflect.ValueOf(cmdEchoSub.GlobalNormalizationFunc()).Pointer() != reflect.ValueOf(rootCmd.GlobalNormalizationFunc()).Pointer() {
		t.Error("cmdPrint and cmdEchoSub should had the normalization function of rootCmd")
	}
}
开发者ID:QuentinPerez,项目名称:delve,代码行数:24,代码来源:cobra_test.go

示例8: WordSepNormalizeFunc

// WordSepNormalizeFunc changes all flags that contain "_" separators
func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
	if strings.Contains(name, "_") {
		return pflag.NormalizedName(strings.Replace(name, "_", "-", -1))
	}
	return pflag.NormalizedName(name)
}
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:7,代码来源:flags.go

示例9: main

func main() {
	trc := newTmplRendererConfig()

	// flags
	fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	fs.StringVar(&trc.outputPath, "out", trc.outputPath, "")

	fs.SetNormalizeFunc(
		func(f *flag.FlagSet, name string) flag.NormalizedName {
			if strings.Contains(name, "_") {
				return flag.NormalizedName(strings.Replace(name, "_", "-", -1))
			}
			return flag.NormalizedName(name)
		},
	)

	// define usage
	fs.Usage = func() {
		goVersion := strings.TrimPrefix(runtime.Version(), "go")
		fmt.Fprintf(os.Stderr, "%s (version=%s, gitrev=%s, go=%s)\n", cliName, Version, GitRev, goVersion)
		/*
			fmt.Fprintf(os.Stderr, "Usage:\n")
			fs.PrintDefaults()
		*/
	}

	// parse
	fs.Parse(os.Args[1:])

	// set from env (if present)
	fs.VisitAll(func(f *flag.Flag) {
		if !f.Changed {
			key := strings.ToUpper(strings.Join(
				[]string{
					cliName,
					strings.Replace(f.Name, "-", "_", -1),
				},
				"_",
			))
			val := os.Getenv(key)
			if val != "" {
				fs.Set(f.Name, val)
			}
		}
	})

	// check if template was provided
	args := fs.Args()
	if len(args) < 1 {
		log.Fatal("Please provide a template")
	}

	// template file
	tmplFile := args[0]

	// check if file exists
	if _, err := os.Stat(tmplFile); os.IsNotExist(err) {
		log.Fatalf("%s", err)
	}

	// template funcs
	funcMap := make(map[string]interface{})
	funcMap["getenv"] = os.Getenv
	funcMap["getEnv"] = os.Getenv
	funcMap["encodeJSON"] = func(i interface{}) string {
		d, err := json.Marshal(i)
		if err != nil {
			log.Fatalf("%v", err)
		}
		return string(d)
	}
	funcMap["getFileContent"] = func(i string) string {
		d, err := ioutil.ReadFile(i)
		if err != nil {
			log.Fatalf("%v", err)
		}
		return string(d)
	}
	funcMap["getFileContentBytes"] = func(i string) []byte {
		d, err := ioutil.ReadFile(i)
		if err != nil {
			log.Fatalf("%v", err)
		}
		return d
	}
	funcMap["gzip"] = func(i []byte) []byte {
		var b bytes.Buffer
		w := gzip.NewWriter(&b)
		if _, err := w.Write(i); err != nil {
			log.Fatalf("%v", err)
		}

		if err := w.Close(); err != nil {
			log.Fatalf("%v", err)
		}

		return b.Bytes()
	}
	funcMap["encodeBase64"] = func(i []byte) string {
		return base64.StdEncoding.EncodeToString(i)
//.........这里部分代码省略.........
开发者ID:glerchundi,项目名称:tmpl-renderer,代码行数:101,代码来源:main.go


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