本文整理汇总了Golang中github.com/spf13/pflag.FlagSet类的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet类的具体用法?Golang FlagSet怎么用?Golang FlagSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlagSet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Bind
// Bind sets the appropriate labels
func (o *RouterSelection) Bind(flag *pflag.FlagSet) {
flag.DurationVar(&o.ResyncInterval, "resync-interval", 10*time.Minute, "The interval at which the route list should be fully refreshed")
flag.StringVar(&o.LabelSelector, "labels", cmdutil.Env("ROUTE_LABELS", ""), "A label selector to apply to the routes to watch")
flag.StringVar(&o.FieldSelector, "fields", cmdutil.Env("ROUTE_FIELDS", ""), "A field selector to apply to routes to watch")
flag.StringVar(&o.ProjectLabelSelector, "project-labels", cmdutil.Env("PROJECT_LABELS", ""), "A label selector to apply to projects to watch; if '*' watches all projects the client can access")
flag.StringVar(&o.NamespaceLabelSelector, "namespace-labels", cmdutil.Env("NAMESPACE_LABELS", ""), "A label selector to apply to namespaces to watch")
}
开发者ID:nitintutlani,项目名称:origin,代码行数:8,代码来源:router.go
示例2: BindFlags
// BindFlags adds any flags that are common to all kubectl sub commands.
func (f *Factory) BindFlags(flags *pflag.FlagSet) {
// any flags defined by external projects (not part of pflags)
util.AddFlagSetToPFlagSet(flag.CommandLine, flags)
// This is necessary as github.com/spf13/cobra doesn't support "global"
// pflags currently. See https://github.com/spf13/cobra/issues/44.
util.AddPFlagSetToPFlagSet(pflag.CommandLine, flags)
// Hack for global access to validation flag.
// TODO: Refactor out after configuration flag overhaul.
if f.flags.Lookup("validate") == nil {
f.flags.Bool("validate", false, "If true, use a schema to validate the input before sending it")
}
// Merge factory's flags
util.AddPFlagSetToPFlagSet(f.flags, flags)
// Globally persistent flags across all subcommands.
// TODO Change flag names to consts to allow safer lookup from subcommands.
// TODO Add a verbose flag that turns on glog logging. Probably need a way
// to do that automatically for every subcommand.
flags.BoolVar(&f.clients.matchVersion, FlagMatchBinaryVersion, false, "Require server version to match client version")
// Normalize all flags that are comming from other packages or pre-configurations
// a.k.a. change all "_" to "-". e.g. glog package
flags.SetNormalizeFunc(util.WordSepNormalizeFunc)
}
开发者ID:kevinvandervlist,项目名称:kubernetes,代码行数:28,代码来源:factory.go
示例3: addFlags
func addFlags(fs *pflag.FlagSet) {
fs.StringVar(&apiServer, "server", "", "API server IP.")
fs.IntVar(&kubeletPort, "kubelet-port", 10250, "Port on which HollowKubelet should be listening.")
fs.IntVar(&kubeletReadOnlyPort, "kubelet-read-only-port", 10255, "Read-only port on which Kubelet is listening.")
fs.StringVar(&nodeName, "name", "fake-node", "Name of this Hollow Node.")
fs.IntVar(&serverPort, "api-server-port", 443, "Port on which API server is listening.")
}
开发者ID:MikaelCluseau,项目名称:kubernetes,代码行数:7,代码来源:hollow-node.go
示例4: rktFlagUsages
func rktFlagUsages(flagSet *pflag.FlagSet) string {
x := new(bytes.Buffer)
flagSet.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 || flag.Hidden {
return
}
format := ""
if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {
format = " -%s, --%s"
} else {
format = " %s --%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "["
}
if flag.Value.Type() == "string" {
// put quotes on the value
format = format + "=%q"
} else {
format = format + "=%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "]"
}
format = format + "\t%s\n"
shorthand := flag.Shorthand
fmt.Fprintf(x, format, shorthand, flag.Name, flag.DefValue, flag.Usage)
})
return x.String()
}
开发者ID:nak3,项目名称:rkt,代码行数:32,代码来源:help.go
示例5: AddFlags
func (s *CloudProviderOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider,
"The provider for cloud services. Empty string for no provider.")
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
"The path to the cloud provider configuration file. Empty string for no configuration file.")
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:7,代码来源:cloudprovider.go
示例6: BindClientConfigSecurityFlags
// BindClientConfigSecurityFlags adds flags for the supplied client config
func BindClientConfigSecurityFlags(config *restclient.Config, flags *pflag.FlagSet) {
flags.BoolVar(&config.Insecure, "insecure-skip-tls-verify", config.Insecure, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.")
flags.StringVar(&config.CertFile, "client-certificate", config.CertFile, "Path to a client certificate file for TLS.")
flags.StringVar(&config.KeyFile, "client-key", config.KeyFile, "Path to a client key file for TLS.")
flags.StringVar(&config.CAFile, "certificate-authority", config.CAFile, "Path to a cert. file for the certificate authority")
flags.StringVar(&config.BearerToken, "token", config.BearerToken, "If present, the bearer token for this request.")
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:clientcmd.go
示例7: updateMounts
// TODO: should this override by destination path, or does swarm handle that?
func updateMounts(flags *pflag.FlagSet, mounts *[]swarm.Mount) {
if !flags.Changed(flagMount) {
return
}
*mounts = flags.Lookup(flagMount).Value.(*MountOpt).Value()
}
开发者ID:agrarianlabs,项目名称:localdiscovery,代码行数:8,代码来源:update.go
示例8: BindSignerCertOptions
func BindSignerCertOptions(options *CreateSignerCertOptions, flags *pflag.FlagSet, prefix string) {
flags.StringVar(&options.CertFile, prefix+"cert", "openshift.local.config/master/ca.crt", "The certificate file.")
flags.StringVar(&options.KeyFile, prefix+"key", "openshift.local.config/master/ca.key", "The key file.")
flags.StringVar(&options.SerialFile, prefix+"serial", "openshift.local.config/master/ca.serial.txt", "The serial file that keeps track of how many certs have been signed.")
flags.StringVar(&options.Name, prefix+"name", DefaultSignerName(), "The name of the signer.")
flags.BoolVar(&options.Overwrite, prefix+"overwrite", options.Overwrite, "Overwrite existing cert files if found. If false, any existing file will be left as-is.")
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:7,代码来源:create_signercert.go
示例9: addFlags
func (c *HollowNodeConfig) addFlags(fs *pflag.FlagSet) {
fs.StringVar(&c.KubeconfigPath, "kubeconfig", "/kubeconfig/kubeconfig", "Path to kubeconfig file.")
fs.IntVar(&c.KubeletPort, "kubelet-port", 10250, "Port on which HollowKubelet should be listening.")
fs.IntVar(&c.KubeletReadOnlyPort, "kubelet-read-only-port", 10255, "Read-only port on which Kubelet is listening.")
fs.StringVar(&c.NodeName, "name", "fake-node", "Name of this Hollow Node.")
fs.IntVar(&c.ServerPort, "api-server-port", 443, "Port on which API server is listening.")
}
开发者ID:pologood,项目名称:kubernetes,代码行数:7,代码来源:hollow-node.go
示例10: updateFlag
func (c *Config) updateFlag(name string, flags *flag.FlagSet) {
if f := flags.Lookup(name); f != nil {
val := c.Viper.Get(name)
strVal := fmt.Sprintf("%v", val)
f.DefValue = strVal
}
}
开发者ID:moypray,项目名称:rexray,代码行数:7,代码来源:config.go
示例11: durationFlag
func durationFlag(
f *pflag.FlagSet, valPtr *time.Duration, flagInfo cliflags.FlagInfo, defaultVal time.Duration,
) {
f.DurationVarP(valPtr, flagInfo.Name, flagInfo.Shorthand, defaultVal, makeUsageString(flagInfo))
setFlagFromEnv(f, flagInfo)
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:7,代码来源:flags.go
示例12: DynStringSet
// DynStringSet creates a `Flag` that represents `map[string]struct{}` which is safe to change dynamically at runtime.
// Unlike `pflag.StringSlice`, consecutive sets don't append to the slice, but override it.
func DynStringSet(flagSet *flag.FlagSet, name string, value []string, usage string) *DynStringSetValue {
set := buildStringSet(value)
dynValue := &DynStringSetValue{ptr: unsafe.Pointer(&set)}
flag := flagSet.VarPF(dynValue, name, "", usage)
MarkFlagDynamic(flag)
return dynValue
}
开发者ID:mwitkow,项目名称:go-flagz,代码行数:9,代码来源:dynstringset.go
示例13: installServiceFlags
func installServiceFlags(flags *pflag.FlagSet) {
flServiceName = flags.String("service-name", "docker", "Set the Windows service name")
flRegisterService = flags.Bool("register-service", false, "Register the service and exit")
flUnregisterService = flags.Bool("unregister-service", false, "Unregister the service and exit")
flRunService = flags.Bool("run-service", false, "")
flags.MarkHidden("run-service")
}
开发者ID:kasisnu,项目名称:docker,代码行数:7,代码来源:service_windows.go
示例14: printFlags
func printFlags(out *bytes.Buffer, flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
if flag.Hidden {
return
}
format := "**--%s**=%s\n\t%s\n\n"
if flag.Value.Type() == "string" {
// put quotes on the value
format = "**--%s**=%q\n\t%s\n\n"
}
defValue := flag.DefValue
if flag.Value.Type() == "duration" {
defValue = "0"
}
if len(flag.Annotations["manpage-def-value"]) > 0 {
defValue = flag.Annotations["manpage-def-value"][0]
}
// Todo, when we mark a shorthand is deprecated, but specify an empty message.
// The flag.ShorthandDeprecated is empty as the shorthand is deprecated.
// Using len(flag.ShorthandDeprecated) > 0 can't handle this, others are ok.
if !(len(flag.ShorthandDeprecated) > 0) && len(flag.Shorthand) > 0 {
format = "**-%s**, " + format
fmt.Fprintf(out, format, flag.Shorthand, flag.Name, defValue, flag.Usage)
} else {
fmt.Fprintf(out, format, flag.Name, defValue, flag.Usage)
}
})
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:31,代码来源:gen_man.go
示例15: deploymentDefaults
func deploymentDefaults(fs *pflag.FlagSet, f *fg.Flags, args []string) {
// Merge Options
fs.VisitAll(func(flag *pflag.Flag) {
if !flag.Changed {
value, ok := f.Options.Get(flag.Name)
if ok {
svalue := fmt.Sprintf("%v", value)
err := fs.Set(flag.Name, svalue)
if err != nil {
Exitf("Error in option '%s': %#v\n", flag.Name, err)
}
}
}
})
if f.Local {
f.StopDelay = 5 * time.Second
f.DestroyDelay = 3 * time.Second
f.SliceDelay = 5 * time.Second
}
if f.JobPath == "" && len(args) >= 1 {
f.JobPath = args[0]
}
if f.ClusterPath == "" && len(args) >= 2 {
f.ClusterPath = args[1]
}
}
开发者ID:pulcy,项目名称:j2,代码行数:28,代码来源:deployment.go
示例16: AddFlags
func (m *NetworkManager) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&m.ConfigFile, "config-file", "/etc/kubernetes/network.conf",
"Network manager configuration")
// DEPRECATED
fs.StringVar(&m.config.KubeUrl, "master", m.config.KubeUrl,
"Kubernetes API endpoint")
}
开发者ID:michaelkuty,项目名称:contrail-kubernetes,代码行数:7,代码来源:server.go
示例17: setupClientCommandLineFlags
func setupClientCommandLineFlags(fs *pflag.FlagSet) {
fs.StringVar(&env, "env", env, "Environment of Apple's APNS and Feedback service gateways. For production use specify \"production\", for testing specify \"sandbox\".")
fs.Uint64Var(&commandsQueueSize, "max-notifications", commandsQueueSize, "Number of notification that can be queued for processing at once. Once the queue is full all requests to raw push notification endpoint will result in 503 Service Unavailable response.")
fs.Uint32Var(&numberOfWorkers, "workers", numberOfWorkers, "Number of workers that concurently process push notifications. Defaults to 2 * Number of CPU cores.")
fs.StringVar(&certifcateFile, "cert", certifcateFile, "Absolute path to certificate file. Certificate is expected be in PEM format.")
fs.StringVar(&certificatePrivateKeyFile, "cert-key", certificatePrivateKeyFile, "Absolute path to certificate private key file. Certificate key is expected be in PEM format.")
}
开发者ID:andrejbaran,项目名称:apns-ms,代码行数:7,代码来源:client.go
示例18: updateMounts
func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error {
mountsByTarget := map[string]mounttypes.Mount{}
if flags.Changed(flagMountAdd) {
values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value()
for _, mount := range values {
if _, ok := mountsByTarget[mount.Target]; ok {
return fmt.Errorf("duplicate mount target")
}
mountsByTarget[mount.Target] = mount
}
}
// Add old list of mount points minus updated one.
for _, mount := range *mounts {
if _, ok := mountsByTarget[mount.Target]; !ok {
mountsByTarget[mount.Target] = mount
}
}
newMounts := []mounttypes.Mount{}
toRemove := buildToRemoveSet(flags, flagMountRemove)
for _, mount := range mountsByTarget {
if _, exists := toRemove[mount.Target]; !exists {
newMounts = append(newMounts, mount)
}
}
sort.Sort(byMountSource(newMounts))
*mounts = newMounts
return nil
}
开发者ID:datawolf,项目名称:docker,代码行数:34,代码来源:update.go
示例19: genFlagResult
func genFlagResult(flags *pflag.FlagSet) []cmdOption {
result := make([]cmdOption, 0)
flags.VisitAll(func(flag *pflag.Flag) {
// Todo, when we mark a shorthand is deprecated, but specify an empty message.
// The flag.ShorthandDeprecated is empty as the shorthand is deprecated.
// Using len(flag.ShorthandDeprecated) > 0 can't handle this, others are ok.
if !(len(flag.ShorthandDeprecated) > 0) && len(flag.Shorthand) > 0 {
opt := cmdOption{
flag.Name,
flag.Shorthand,
flag.DefValue,
forceMultiLine(flag.Usage),
}
result = append(result, opt)
} else {
opt := cmdOption{
Name: flag.Name,
DefaultValue: forceMultiLine(flag.DefValue),
Usage: forceMultiLine(flag.Usage),
}
result = append(result, opt)
}
})
return result
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:27,代码来源:gen_kubectl_yaml.go
示例20: manPrintFlags
func manPrintFlags(out *bytes.Buffer, flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 {
return
}
format := ""
if len(flag.Shorthand) > 0 {
format = "**-%s**, **--%s**"
} else {
format = "%s**--%s**"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "["
}
if flag.Value.Type() == "string" {
// put quotes on the value
format = format + "=%q"
} else {
format = format + "=%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "]"
}
format = format + "\n\t%s\n\n"
fmt.Fprintf(out, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)
})
}
开发者ID:pgruenbacher,项目名称:cobra,代码行数:27,代码来源:man_docs.go
注:本文中的github.com/spf13/pflag.FlagSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论