當前位置: 首頁>>代碼示例>>Golang>>正文


Golang viper.BindPFlags函數代碼示例

本文整理匯總了Golang中github.com/spf13/viper.BindPFlags函數的典型用法代碼示例。如果您正苦於以下問題:Golang BindPFlags函數的具體用法?Golang BindPFlags怎麽用?Golang BindPFlags使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BindPFlags函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	RootCmd.PersistentFlags().Bool(showLibmachineLogs, false, "Whether or not to show logs from libmachine.")
	RootCmd.AddCommand(configCmd.ConfigCmd)
	pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
	viper.BindPFlags(RootCmd.PersistentFlags())
	cobra.OnInitialize(initConfig)
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:7,代碼來源:root.go

示例2: init

func init() {
	// root and persistent flags
	rootCmd.PersistentFlags().String("log-level", "info", "one of debug, info, warn, error, or fatal")
	rootCmd.PersistentFlags().String("log-format", "text", "specify output (text or json)")

	// build flags
	buildCmd.Flags().String("shell", "bash", "shell to use for executing build scripts")
	buildCmd.Flags().Int("concurrent-jobs", runtime.NumCPU(), "number of packages to build at once")
	buildCmd.Flags().String("stream-logs-for", "", "stream logs from a single package")

	cwd, err := os.Getwd()
	if err != nil {
		logrus.WithField("error", err).Warning("could not get working directory")
	}
	rootCmd.PersistentFlags().String("search", cwd, "where to look for package definitions")
	buildCmd.Flags().String("output", path.Join(cwd, "out"), "where to place output packages")
	buildCmd.Flags().String("logs", path.Join(cwd, "logs"), "where to place build logs")
	buildCmd.Flags().String("cache", path.Join(cwd, ".hammer-cache"), "where to cache downloads")
	buildCmd.Flags().Bool("skip-cleanup", false, "skip cleanup step")

	for _, flags := range []*pflag.FlagSet{rootCmd.PersistentFlags(), buildCmd.Flags()} {
		err := viper.BindPFlags(flags)
		if err != nil {
			logrus.WithField("error", err).Fatal("could not bind flags")
		}
	}
}
開發者ID:asteris-llc,項目名稱:hammer,代碼行數:27,代碼來源:main.go

示例3: init

func init() {
	buildCmd.AddCommand(buildImagesCmd)

	buildImagesCmd.PersistentFlags().BoolP(
		"no-build",
		"N",
		false,
		"If specified, the Dockerfile and assets will be created, but the image won't be built.",
	)

	buildImagesCmd.PersistentFlags().BoolP(
		"force",
		"F",
		false,
		"If specified, image creation will proceed even when images already exist.",
	)

	buildImagesCmd.PersistentFlags().StringP(
		"patch-properties-release",
		"P",
		"",
		"Used to designate a \"patch-properties\" psuedo-job in a particular release.  Format: RELEASE/JOB.",
	)

	viper.BindPFlags(buildImagesCmd.PersistentFlags())
}
開發者ID:hpcloud,項目名稱:fissile,代碼行數:26,代碼來源:build-images.go

示例4: newConfig

func newConfig() *Conf {
	c := new(Conf)
	c.ldapViper = viper.New()
	c.ldapConfig = &LdapConfig{}
	c.notificationConfigs = []NotificationServiceConfig{}

	viper.SetConfigName("indispenso")
	viper.SetEnvPrefix("ind")

	// Defaults
	viper.SetDefault("Token", "")
	viper.SetDefault("Hostname", getDefaultHostName())
	viper.SetDefault("UseAutoTag", true)
	viper.SetDefault("ServerEnabled", false)
	viper.SetDefault("Home", defaultHomePath)
	viper.SetDefault("Debug", false)
	viper.SetDefault("ServerPort", 897)
	viper.SetDefault("EndpointURI", "")
	viper.SetDefault("SslCertFile", "cert.pem")
	viper.SetDefault("SslPrivateKeyFile", "key.pem")
	viper.SetDefault("AutoGenerateCert", true)
	viper.SetDefault("ClientPort", 898)
	viper.SetDefault("EnableLdap", false)
	viper.SetDefault("LdapConfigFile", "")

	//Flags
	c.confFlags = pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)

	configFile := c.confFlags.StringP("config", "c", "", "Config file location default is /etc/indispenso/indispenso.{json,toml,yaml,yml,properties,props,prop}")
	c.confFlags.BoolP("serverEnabled", "s", false, "Define if server module should be started or not")
	c.confFlags.BoolP("debug", "d", false, "Enable debug mode")
	c.confFlags.StringP("home", "p", defaultHomePath, "Home directory where all config files are located")
	c.confFlags.StringP("endpointUri", "e", "", "URI of server interface, used by client")
	c.confFlags.StringP("token", "t", "", "Secret token")
	c.confFlags.StringP("hostname", "i", getDefaultHostName(), "Hostname that is use to identify itself")
	c.confFlags.BoolP("enableLdap", "l", false, "Enable LDAP authentication")
	c.confFlags.BoolP("help", "h", false, "Print help message")

	c.confFlags.Parse(os.Args[1:])
	if len(*configFile) > 2 {
		viper.SetConfigFile(*configFile)
	} else {
		legacyConfigFile := "/etc/indispenso/indispenso.conf"
		if _, err := os.Stat(legacyConfigFile); err == nil {
			viper.SetConfigFile(legacyConfigFile)
			viper.SetConfigType("yaml")
		}
	}
	viper.BindPFlags(c.confFlags)
	viper.AutomaticEnv()

	viper.ReadInConfig()

	c.setupHome(nil, viper.GetString("Home"))
	c.setupHome(c.ldapViper, viper.GetString("Home"))

	c.SetupNotificationConfig("slack", &SlackNotifyConfig{})
	c.Update()
	return c
}
開發者ID:RobinUS2,項目名稱:indispenso,代碼行數:60,代碼來源:conf.go

示例5: setupConfig

func setupConfig() {
	agentCmd.Flags().StringVar(&configFile, "config", "", "specify a configuration file")

	err := viper.BindPFlags(agentCmd.Flags())
	if err != nil {
		log.Errorf("Error binding pflags: %v", err)
	}
}
開發者ID:luizbafilho,項目名稱:fusis,代碼行數:8,代碼來源:agent.go

示例6: setupBalancerCmdFlags

func setupBalancerCmdFlags(cmd *cobra.Command) {
	cmd.Flags().StringVar(&configFile, "config", "", "specify a configuration file")
	cmd.Flags().StringVar(&conf.LogLevel, "log-level", "", "specify a log level")
	cmd.Flags().BoolVarP(&conf.EnableHealthChecks, "enable-health-checks", "", true, "enables health checking on destinations")
	cmd.Flags().StringVarP(&conf.StorePrefix, "store-prefix", "", "fusis", "configures the prefix used by the store")
	cmd.Flags().StringVarP(&conf.StoreAddress, "store-address", "", "consul://localhost:8500", "configures the store address")

	err := viper.BindPFlags(cmd.Flags())
	if err != nil {
		log.Errorf("Error binding pflags: %v", err)
	}
}
開發者ID:luizbafilho,項目名稱:fusis,代碼行數:12,代碼來源:balancer.go

示例7: init

func init() {
	docsCmd.AddCommand(docsMarkdownCmd)

	docsMarkdownCmd.PersistentFlags().StringP(
		"md-output-dir",
		"O",
		"./docs",
		"Specifies a location where markdown documentation will be generated.",
	)

	viper.BindPFlags(docsMarkdownCmd.PersistentFlags())
}
開發者ID:hpcloud,項目名稱:fissile,代碼行數:12,代碼來源:docs-markdown.go

示例8: init

func init() {
	docsCmd.AddCommand(docsAutocompleteCmd)

	docsAutocompleteCmd.PersistentFlags().StringP(
		"output-file",
		"O",
		"./fissile-autocomplete.sh",
		"Specifies a file location where a bash autocomplete script will be generated.",
	)

	viper.BindPFlags(docsAutocompleteCmd.PersistentFlags())
}
開發者ID:hpcloud,項目名稱:fissile,代碼行數:12,代碼來源:docs-autocomplete.go

示例9: init

func init() {
	docsCmd.AddCommand(docsManCmd)

	docsManCmd.PersistentFlags().StringP(
		"man-output-dir",
		"O",
		"./man",
		"Specifies a location where man pages will be generated.",
	)

	viper.BindPFlags(docsManCmd.PersistentFlags())
}
開發者ID:hpcloud,項目名稱:fissile,代碼行數:12,代碼來源:docs-man.go

示例10: init

func init() {
	buildLayerCmd.AddCommand(buildLayerCompilationCmd)

	buildLayerCompilationCmd.PersistentFlags().BoolP(
		"debug",
		"D",
		false,
		"If specified, the docker container used to build the layer won't be destroyed on failure.",
	)

	viper.BindPFlags(buildLayerCompilationCmd.PersistentFlags())
}
開發者ID:hpcloud,項目名稱:fissile,代碼行數:12,代碼來源:build-layer-compilation.go

示例11: main

func main() {
	rootCmd := &cobra.Command{
		Use:   "mantl-api",
		Short: "runs the mantl-api",
		Run: func(cmd *cobra.Command, args []string) {
			start()
		},
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			readConfigFile()
			setupLogging()
		},
	}

	rootCmd.PersistentFlags().String("log-level", "info", "one of debug, info, warn, error, or fatal")
	rootCmd.PersistentFlags().String("log-format", "text", "specify output (text or json)")
	rootCmd.PersistentFlags().String("consul", "http://localhost:8500", "Consul Api address")
	rootCmd.PersistentFlags().String("marathon", "", "Marathon Api address")
	rootCmd.PersistentFlags().String("marathon-user", "", "Marathon Api user")
	rootCmd.PersistentFlags().String("marathon-password", "", "Marathon Api password")
	rootCmd.PersistentFlags().Bool("marathon-no-verify-ssl", false, "Marathon SSL verification")
	rootCmd.PersistentFlags().String("mesos", "", "Mesos Api address")
	rootCmd.PersistentFlags().String("mesos-principal", "", "Mesos principal for framework authentication")
	rootCmd.PersistentFlags().String("mesos-secret", "", "Mesos secret for framework authentication")
	rootCmd.PersistentFlags().Bool("mesos-no-verify-ssl", false, "Mesos SSL verification")
	rootCmd.PersistentFlags().String("listen", ":4001", "mantl-api listen address")
	rootCmd.PersistentFlags().String("zookeeper", "", "Comma-delimited list of zookeeper servers")
	rootCmd.PersistentFlags().Bool("force-sync", false, "Force a synchronization of all sources")
	rootCmd.PersistentFlags().String("config-file", "", "The path to a configuration file")

	for _, flags := range []*pflag.FlagSet{rootCmd.PersistentFlags()} {
		err := viper.BindPFlags(flags)
		if err != nil {
			log.WithField("error", err).Fatal("could not bind flags")
		}
	}

	viper.SetEnvPrefix("mantl_api")
	viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
	viper.AutomaticEnv()

	syncCommand := &cobra.Command{
		Use:   "sync",
		Short: "Synchronize universe repositories",
		Long:  "Forces a synchronization of all configured sources",
		Run: func(cmd *cobra.Command, args []string) {
			sync(nil, true)
		},
	}
	rootCmd.AddCommand(syncCommand)

	rootCmd.Execute()
}
開發者ID:nikolayvoronchikhin,項目名稱:mantl-api,代碼行數:52,代碼來源:main.go

示例12: init

func init() {
	cobra.OnInitialize(initConfig, initLogging, lockMemory)

	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is /etc/sysconfig/vaultfs)")

	// logging flags
	RootCmd.PersistentFlags().String("log-level", "info", "log level (one of fatal, error, warn, info, or debug)")
	RootCmd.PersistentFlags().String("log-format", "text", "log level (one of text or json)")
	RootCmd.PersistentFlags().String("log-destination", "stdout:", "log destination (file:/your/output, stdout:, journald:, or syslog://[email protected]:port#protocol)")

	if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
		logrus.WithError(err).Fatal("could not bind flags")
	}
}
開發者ID:asteris-llc,項目名稱:vaultfs,代碼行數:14,代碼來源:root.go

示例13: init

func init() {
	startCmd.Flags().String(isoURL, constants.DefaultIsoUrl, "Location of the minikube iso")
	startCmd.Flags().String(vmDriver, constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
	startCmd.Flags().Int(memory, constants.DefaultMemory, "Amount of RAM allocated to the minikube VM")
	startCmd.Flags().Int(cpus, constants.DefaultCPUS, "Number of CPUs allocated to the minikube VM")
	startCmd.Flags().String(humanReadableDiskSize, constants.DefaultDiskSize, "Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g)")
	startCmd.Flags().String(hostOnlyCIDR, "192.168.99.1/24", "The CIDR to be used for the minikube VM (only supported with Virtualbox driver)")
	startCmd.Flags().StringSliceVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
	startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon")
	startCmd.Flags().StringSliceVar(&registryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
	startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will (ex: v1.2.3) \n OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64)")
	viper.BindPFlags(startCmd.Flags())
	RootCmd.AddCommand(startCmd)
}
開發者ID:gashcrumb,項目名稱:gofabric8,代碼行數:14,代碼來源:start.go

示例14: cli

func cli(flags *pflag.FlagSet, run func(cmd *cobra.Command, args []string)) *cobra.Command {
	// Create command
	cmd := &cobra.Command{
		Use:   "trainsporter",
		Short: "Trainspotter",
		Long:  "Trainspotter",
		Run:   run,
	}

	// Register flags with command
	cmd.Flags().AddFlagSet(flags)

	// Bind to viper
	viper.BindPFlags(flags)

	return cmd
}
開發者ID:krak3n,項目名稱:trainspotter,代碼行數:17,代碼來源:main.go

示例15: init

func init() {
	startCmd.Flags().String(isoURL, constants.DefaultIsoUrl, "Location of the minishift iso")
	startCmd.Flags().String(vmDriver, constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
	startCmd.Flags().Int(memory, constants.DefaultMemory, "Amount of RAM allocated to the minishift VM")
	startCmd.Flags().Int(cpus, constants.DefaultCPUS, "Number of CPUs allocated to the minishift VM")
	startCmd.Flags().String(humanReadableDiskSize, constants.DefaultDiskSize, "Disk size allocated to the minishift VM (format: <number>[<unit>], where unit = b, k, m or g)")
	startCmd.Flags().String(hostOnlyCIDR, "192.168.99.1/24", "The CIDR to be used for the minishift VM (only supported with Virtualbox driver)")
	startCmd.Flags().StringSliceVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
	startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", []string{"172.30.0.0/16"}, "Insecure Docker registries to pass to the Docker daemon")
	startCmd.Flags().StringSliceVar(&registryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
	startCmd.Flags().Bool(deployRegistry, true, "Should the OpenShift internal Docker registry be deployed?")
	startCmd.Flags().Bool(deployRouter, false, "Should the OpenShift router be deployed?")

	viper.BindPFlags(startCmd.Flags())

	RootCmd.AddCommand(startCmd)
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:17,代碼來源:start.go


注:本文中的github.com/spf13/viper.BindPFlags函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。