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


Golang Command.PersistentFlags方法代码示例

本文整理汇总了Golang中github.com/spf13/cobra.Command.PersistentFlags方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.PersistentFlags方法的具体用法?Golang Command.PersistentFlags怎么用?Golang Command.PersistentFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/spf13/cobra.Command的用法示例。


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

示例1: isVerbose

func isVerbose(cmd *cobra.Command) bool {
	verbose, err := cmd.PersistentFlags().GetBool("verbose")
	if err != nil {
		panic(err)
	}
	return verbose
}
开发者ID:jcnnghm,项目名称:cmdtrack,代码行数:7,代码来源:history.go

示例2: collectFlags

func collectFlags(v *viper.Viper, cmd *cobra.Command) {
	v.BindPFlags(cmd.PersistentFlags())
	v.BindPFlags(cmd.Flags())
	for _, cmd := range cmd.Commands() {
		collectFlags(v, cmd)
	}
}
开发者ID:omise,项目名称:omise-go,代码行数:7,代码来源:config.go

示例3: AddFlags

// AddFlags adds cli flags to logvac
func AddFlags(cmd *cobra.Command) {
	// collectors
	cmd.Flags().StringVarP(&ListenHttp, "listen-http", "a", ListenHttp, "API listen address (same endpoint for http log collection)")
	cmd.Flags().StringVarP(&ListenUdp, "listen-udp", "u", ListenUdp, "UDP log collection endpoint")
	cmd.Flags().StringVarP(&ListenTcp, "listen-tcp", "t", ListenTcp, "TCP log collection endpoint")

	// drains
	cmd.Flags().StringVarP(&PubAddress, "pub-address", "p", PubAddress, "Log publisher (mist) address (\"mist://127.0.0.1:1445\")")
	cmd.Flags().StringVarP(&PubAuth, "pub-auth", "P", PubAuth, "Log publisher (mist) auth token")
	cmd.Flags().StringVarP(&DbAddress, "db-address", "d", DbAddress, "Log storage address")

	// authenticator
	cmd.PersistentFlags().StringVarP(&AuthAddress, "auth-address", "A", AuthAddress, "Address or file location of authentication db. ('boltdb:///var/db/logvac.bolt' or 'postgresql://127.0.0.1')")

	// other
	cmd.Flags().StringVarP(&CorsAllow, "cors-allow", "C", CorsAllow, "Sets the 'Access-Control-Allow-Origin' header")
	cmd.Flags().StringVarP(&LogKeep, "log-keep", "k", LogKeep, "Age or number of logs to keep per type '{\"app\":\"2w\", \"deploy\": 10}' (int or X(m)in, (h)our,  (d)ay, (w)eek, (y)ear)")
	cmd.Flags().StringVarP(&LogLevel, "log-level", "l", LogLevel, "Level at which to log")
	cmd.Flags().StringVarP(&LogType, "log-type", "L", LogType, "Default type to apply to incoming logs (commonly used: app|deploy)")
	cmd.Flags().StringVarP(&Token, "token", "T", Token, "Administrative token to add/remove 'X-USER-TOKEN's used to pub/sub via http")
	cmd.Flags().BoolVarP(&Server, "server", "s", Server, "Run as server")
	cmd.Flags().BoolVarP(&Insecure, "insecure", "i", Insecure, "Don't use TLS (used for testing)")
	cmd.Flags().BoolVarP(&Version, "version", "v", Version, "Print version info and exit")

	Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
}
开发者ID:nanopack,项目名称:logvac,代码行数:27,代码来源:config.go

示例4: initializeFlags

func initializeFlags(cmd *cobra.Command) {
	persFlagKeys := []string{"verbose", "logFile"}
	flagKeys := []string{
		"cleanDestinationDir",
		"buildDrafts",
		"buildFuture",
		"buildExpired",
		"uglyURLs",
		"canonifyURLs",
		"disable404",
		"disableRSS",
		"disableSitemap",
		"enableRobotsTXT",
		"enableGitInfo",
		"pluralizeListTitles",
		"preserveTaxonomyNames",
		"ignoreCache",
		"forceSyncStatic",
		"noTimes",
	}

	for _, key := range persFlagKeys {
		setValueFromFlag(cmd.PersistentFlags(), key)
	}
	for _, key := range flagKeys {
		setValueFromFlag(cmd.Flags(), key)
	}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:28,代码来源:hugo.go

示例5: RegisterCommands

// RegisterCommands registers the resource action CLI commands.
func RegisterCommands(app *cobra.Command, c *client.Client) {
	var command, sub *cobra.Command
	command = &cobra.Command{
		Use:   "create",
		Short: `creates a bottle`,
	}
	tmp1 := new(CreateBottleCommand)
	sub = &cobra.Command{
		Use:   `bottle ["/bottles"]`,
		Short: `A wine bottle`,
		RunE:  func(cmd *cobra.Command, args []string) error { return tmp1.Run(c, args) },
	}
	tmp1.RegisterFlags(sub, c)
	sub.PersistentFlags().BoolVar(&tmp1.PrettyPrint, "pp", false, "Pretty print response body")
	command.AddCommand(sub)
	app.AddCommand(command)
	command = &cobra.Command{
		Use:   "show",
		Short: `shows a bottle`,
	}
	tmp2 := new(ShowBottleCommand)
	sub = &cobra.Command{
		Use:   `bottle ["/bottles/ID"]`,
		Short: `A wine bottle`,
		RunE:  func(cmd *cobra.Command, args []string) error { return tmp2.Run(c, args) },
	}
	tmp2.RegisterFlags(sub, c)
	sub.PersistentFlags().BoolVar(&tmp2.PrettyPrint, "pp", false, "Pretty print response body")
	command.AddCommand(sub)
	app.AddCommand(command)
}
开发者ID:Rahmadkurniawan,项目名称:2016-talks,代码行数:32,代码来源:commands.go

示例6: SetupRootCommand

// SetupRootCommand sets default usage, help, and error handling for the
// root command.
func SetupRootCommand(rootCmd *cobra.Command) {
	rootCmd.SetUsageTemplate(usageTemplate)
	rootCmd.SetHelpTemplate(helpTemplate)
	rootCmd.SetFlagErrorFunc(FlagErrorFunc)

	rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
	rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
}
开发者ID:HuKeping,项目名称:docker,代码行数:10,代码来源:cobra.go

示例7: testBindClientConfig

func testBindClientConfig(cmd *cobra.Command) ClientConfig {
	loadingRules := &ClientConfigLoadingRules{}
	cmd.PersistentFlags().StringVar(&loadingRules.ExplicitPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")

	overrides := &ConfigOverrides{}
	BindOverrideFlags(overrides, cmd.PersistentFlags(), RecommendedConfigOverrideFlags(""))
	clientConfig := NewInteractiveDeferredLoadingClientConfig(loadingRules, overrides, os.Stdin)

	return clientConfig
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:10,代码来源:merged_client_builder_test.go

示例8: addSubmitFlags

func addSubmitFlags(cmd *cobra.Command, config *SubmitQueueConfig) {
	cmd.Flags().BoolVar(&config.Once, "once", false, "If true, run one loop and exit")
	cmd.Flags().StringSliceVar(&config.JenkinsJobs, "jenkins-jobs", []string{"kubernetes-e2e-gce", "kubernetes-e2e-gke-ci", "kubernetes-build", "kubernetes-e2e-gce-parallel", "kubernetes-e2e-gce-autoscaling", "kubernetes-e2e-gce-reboot", "kubernetes-e2e-gce-scalability"}, "Comma separated list of jobs in Jenkins to use for stability testing")
	cmd.Flags().StringVar(&config.JenkinsHost, "jenkins-host", "", "The URL for the jenkins job to watch")
	cmd.Flags().StringSliceVar(&config.RequiredStatusContexts, "required-contexts", []string{"cla/google", "Shippable", "continuous-integration/travis-ci/pr"}, "Comma separate list of status contexts required for a PR to be considered ok to merge")
	cmd.Flags().DurationVar(&config.PollPeriod, "poll-period", 30*time.Minute, "The period for running the submit-queue")
	cmd.Flags().StringVar(&config.Address, "address", ":8080", "The address to listen on for HTTP Status")
	cmd.Flags().StringVar(&config.DontRequireE2ELabel, "dont-require-e2e-label", "e2e-not-required", "If non-empty, a PR with this label will be merged automatically without looking at e2e results")
	cmd.Flags().StringVar(&config.E2EStatusContext, "e2e-status-context", "Jenkins GCE e2e", "The name of the github status context for the e2e PR Builder")
	cmd.Flags().StringVar(&config.WWWRoot, "www", "", "Path to static web files to serve from the webserver")
	cmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine)
}
开发者ID:tiran,项目名称:kubernetes-contrib,代码行数:12,代码来源:submit-queue.go

示例9: globalFlags

func (c *CLI) globalFlags(cmd *cobra.Command) *flag.FlagSet {
	fs := &flag.FlagSet{}
	if cmd.HasParent() {
		fs.AddFlagSet(cmd.InheritedFlags())
		if fs.Lookup("help") == nil && cmd.Flag("help") != nil {
			fs.AddFlag(cmd.Flag("help"))
		}
	} else {
		fs.AddFlagSet(cmd.PersistentFlags())
	}
	return c.sansDriverFlags(c.sansAdditionalFlags(fs))
}
开发者ID:nutmegdevelopment,项目名称:rexray,代码行数:12,代码来源:usage.go

示例10: testBindClientConfig

func testBindClientConfig(cmd *cobra.Command) ClientConfig {
	loadingRules := NewClientConfigLoadingRules()
	loadingRules.EnvVarPath = ""
	loadingRules.HomeDirectoryPath = ""
	loadingRules.CurrentDirectoryPath = ""
	cmd.PersistentFlags().StringVar(&loadingRules.CommandLinePath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")

	overrides := &ConfigOverrides{}
	overrides.BindFlags(cmd.PersistentFlags(), RecommendedConfigOverrideFlags(""))
	clientConfig := NewInteractiveDeferredLoadingClientConfig(loadingRules, overrides, os.Stdin)

	return clientConfig
}
开发者ID:nhr,项目名称:kubernetes,代码行数:13,代码来源:merged_client_builder_test.go

示例11: SetupRootCommand

// SetupRootCommand sets default usage, help, and error handling for the
// root command.
func SetupRootCommand(rootCmd *cobra.Command) {
	cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
	cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
	cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
	cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)

	rootCmd.SetUsageTemplate(usageTemplate)
	rootCmd.SetHelpTemplate(helpTemplate)
	rootCmd.SetFlagErrorFunc(FlagErrorFunc)

	rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
	rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:15,代码来源:cobra.go

示例12: AddFlags

func AddFlags(cmd *cobra.Command) {
	cmd.Flags().StringVarP(&SshListenAddress, "ssh-address", "", ":2222", "[server] SshListenAddress")
	cmd.Flags().StringVarP(&HttpListenAddress, "http-address", "", ":8080", "[server] HttpListenAddress")
	cmd.Flags().StringVarP(&KeyPath, "key-path", "", "", "[server] KeyPath")
	cmd.Flags().StringVarP(&RepoType, "repo-type", "", "", "[server] RepoType")
	cmd.Flags().StringVarP(&RepoLocation, "repo-location", "", "", "[server] RepoLocation")
	cmd.Flags().StringVarP(&KeyAuthType, "key-auth-type", "", "", "[server] KeyAuthType")
	cmd.Flags().StringVarP(&KeyAuthLocation, "key-auth-location", "", "", "[server] KeyAuthLocation")
	cmd.Flags().StringVarP(&PassAuthType, "pass-auth-type", "", "", "[server] PassAuthType")
	cmd.Flags().StringVarP(&PassAuthLocation, "pass-auth-location", "", "", "[server] PassAuthLocation")
	cmd.Flags().StringVarP(&DeployType, "deploy-type", "", "", "[server] DeployType")
	cmd.Flags().StringVarP(&DeployLocation, "deploy-location", "", "", "[server] DeployLocation")
	cmd.PersistentFlags().StringVarP(&Token, "token", "", "secret", "Token security")
}
开发者ID:Lanzafame,项目名称:butter,代码行数:14,代码来源:config.go

示例13: CommandFor

// CommandFor returns the appropriate command for this base name,
// or the OpenShift CLI command.
func CommandFor(basename string) *cobra.Command {
	var cmd *cobra.Command

	out := os.Stdout

	// Make case-insensitive and strip executable suffix if present
	if runtime.GOOS == "windows" {
		basename = strings.ToLower(basename)
		basename = strings.TrimSuffix(basename, ".exe")
	}

	switch basename {
	case "kubectl":
		cmd = NewCmdKubectl(basename, out)
	default:
		cmd = NewCommandCLI(basename, basename, out)
	}

	if cmd.UsageFunc() == nil {
		templates.ActsAsRootCommand(cmd)
	}
	flagtypes.GLog(cmd.PersistentFlags())

	return cmd
}
开发者ID:nikkomega,项目名称:origin,代码行数:27,代码来源:cli.go

示例14: addWhitelistCommand

func (sq *SubmitQueue) addWhitelistCommand(root *cobra.Command, config *github_util.Config) {
	genCommitters := &cobra.Command{
		Use:   "gencommiters",
		Short: "Generate the list of people with commit access",
		RunE: func(_ *cobra.Command, _ []string) error {
			if err := config.PreExecute(); err != nil {
				return err
			}
			return sq.doGenCommitters(config)
		},
	}
	root.PersistentFlags().StringVar(&sq.Whitelist, "user-whitelist", "./whitelist.txt", "Path to a whitelist file that contains users to auto-merge.  Required.")
	root.PersistentFlags().StringVar(&sq.Committers, "committers", "./committers.txt", "File in which the list of authorized committers is stored; only used if this list cannot be gotten at run time.  (Merged with whitelist; separate so that it can be auto-generated)")

	root.AddCommand(genCommitters)
}
开发者ID:jojimt,项目名称:contrib,代码行数:16,代码来源:user-lists.go

示例15: addWhitelistCommand

func addWhitelistCommand(root *cobra.Command, config *SubmitQueueConfig) {
	genCommitters := &cobra.Command{
		Use:   "gencommiters",
		Short: "Generate the list of people with commit access",
		RunE: func(_ *cobra.Command, _ []string) error {
			if err := config.PreExecute(); err != nil {
				return err
			}
			return config.doGenCommitters()
		},
	}
	root.PersistentFlags().StringVar(&config.Whitelist, "user-whitelist", "./whitelist.txt", "Path to a whitelist file that contains users to auto-merge.  Required.")
	root.PersistentFlags().StringVar(&config.Committers, "committers", "./committers.txt", "File in which the list of authorized committers is stored; only used if this list cannot be gotten at run time.  (Merged with whitelist; separate so that it can be auto-generated)")
	root.Flags().StringVar(&config.WhitelistOverride, "whitelist-override-label", "ok-to-merge", "Github label, if present on a PR it will be merged even if the author isn't in the whitelist")

	root.AddCommand(genCommitters)
}
开发者ID:RobertATX,项目名称:contrib,代码行数:17,代码来源:user-lists.go


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