本文整理汇总了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)
}
示例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")
}
}
}
示例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())
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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())
}
示例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())
}
示例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())
}
示例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())
}
示例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()
}
示例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")
}
}
示例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(®istryMirror, "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)
}
示例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
}
示例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(®istryMirror, "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)
}