• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang viper.BindPFlag函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: init

func init() {
	RootCmd.AddCommand(serveCmd)

	// @NOTE: Do not set the default values here, that doesn't work correctly!
	serveCmd.Flags().BoolP("daemon", "d", false, "Run as a daemon and detach from terminal")
	serveCmd.Flags().StringP("address", "a", "", "Set address:port to listen on")
	serveCmd.Flags().StringP("domain", "e", "", "Set domain to use with cookies")
	serveCmd.Flags().StringP("databasepath", "f", "", "Set path to database where the user infos are stored")
	serveCmd.Flags().IntP("cookiemaxage", "m", 4, "Set magical cookie's lifetime before it expires (in hours)")
	serveCmd.Flags().StringP("cookiesecret", "c", "", "Secret string to use in signing cookies")

	viper.BindPFlag("address", serveCmd.Flags().Lookup("address"))
	viper.BindPFlag("domain", serveCmd.Flags().Lookup("domain"))
	viper.BindPFlag("databasepath", serveCmd.Flags().Lookup("databasepath"))
	viper.BindPFlag("cookiemaxage", serveCmd.Flags().Lookup("cookiemaxage"))
	viper.BindPFlag("cookiesecret", serveCmd.Flags().Lookup("cookiesecret"))

	viper.SetDefault("address", "127.0.0.1:9434")
	viper.SetDefault("domain", ".secure.mydomain.eu")
	viper.SetDefault("databasepath", "./database.json")
	viper.SetDefault("cookiemaxage", 4)
	viper.SetDefault("cookiesecret", "CHOOSE-A-SECRET-YOURSELF")

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// serveCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	// serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}
开发者ID:lstep,项目名称:2fanginx,代码行数:34,代码来源:serve.go


示例2: init

func init() {
	RootCmd.AddCommand(devicesCmd)
	devicesCmd.PersistentFlags().String("app-id", "", "The app ID to use")
	viper.BindPFlag("app-id", devicesCmd.PersistentFlags().Lookup("app-id"))
	devicesCmd.PersistentFlags().String("app-eui", "", "The app EUI to use")
	viper.BindPFlag("app-eui", devicesCmd.PersistentFlags().Lookup("app-eui"))
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:devices.go


示例3: init

func init() {
	cobra.OnInitialize(initConfig)

	// Here you will define your flags and configuration settings.
	// Cobra supports Persistent Flags, which, if defined here,
	// will be global for your application.

	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.nessusControl.yaml)")
	// Cobra also supports local flags, which will only run
	// when this action is called directly.
	RootCmd.PersistentFlags().StringP("username", "u", "admin", "The username to log into Nessus.")
	RootCmd.PersistentFlags().StringP("password", "a", "Th1sSh0u1dB3AStr0ngP422w0rd", "The password to use to log into Nessus.")
	RootCmd.PersistentFlags().StringP("hostname", "o", "127.0.0.1", "The host where Nessus is located.")
	RootCmd.PersistentFlags().StringP("port", "p", "8834", "The port number used to connect to Nessus.")
	RootCmd.PersistentFlags().BoolP("debug", "d", false, "Use this flag to enable debug mode")

	viper.BindPFlag("auth.username", RootCmd.PersistentFlags().Lookup("username"))
	viper.SetDefault("auth.username", "admin")
	viper.BindPFlag("auth.password", RootCmd.PersistentFlags().Lookup("password"))
	viper.SetDefault("auth.password", "Th1sSh0u1dB3AStr0ngP422w0rd")
	viper.BindPFlag("nessusLocation.hostname", RootCmd.PersistentFlags().Lookup("hostname"))
	viper.SetDefault("nessusLocation.hostname", "127.0.0.1")
	viper.BindPFlag("nessusLocation.port", RootCmd.PersistentFlags().Lookup("port"))
	viper.SetDefault("nessusLocation.port", "8834")
	viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug"))
	viper.SetDefault("debug", "8834")
}
开发者ID:kkirsche,项目名称:nessusControl,代码行数:27,代码来源:root.go


示例4: init

func init() {
	cobra.OnInitialize(initConfig)
	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
	RootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "", "base project directory, e.g. github.com/spf13/")
	RootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "Author name for copyright attribution")
	RootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "Name of license for the project (can provide `licensetext` in config)")
	RootCmd.PersistentFlags().Bool("viper", true, "Use Viper for configuration")
	viper.BindPFlag("author", RootCmd.PersistentFlags().Lookup("author"))
	viper.BindPFlag("projectbase", RootCmd.PersistentFlags().Lookup("projectbase"))
	viper.BindPFlag("useViper", RootCmd.PersistentFlags().Lookup("viper"))
	viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
	viper.SetDefault("license", "apache")
	viper.SetDefault("licenseText", `
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
`)
}
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:25,代码来源:root.go


示例5: init

func init() {
	GrasshopperCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
	GrasshopperCmd.PersistentFlags().BoolVarP(&Quiet, "quiet", "q", false, "quiet output")
	GrasshopperCmd.PersistentFlags().BoolVarP(&Log, "log", "l", true, "write logging output to file")
	GrasshopperCmd.PersistentFlags().BoolVarP(&Experimental, "experimental", "x", true, "write experimental output to stdout")

	grasshopperCmdV = GrasshopperCmd

	viper.BindPFlag("verbose", GrasshopperCmd.PersistentFlags().Lookup("verbose"))
	viper.BindPFlag("quiet", GrasshopperCmd.PersistentFlags().Lookup("quiet"))
	viper.BindPFlag("log", GrasshopperCmd.PersistentFlags().Lookup("log"))
	viper.BindPFlag("experimental", GrasshopperCmd.PersistentFlags().Lookup("experimental"))

	if Log {
		jww.SetLogFile("grasshopper.log")
	}

	if Quiet {
		jww.SetStdoutThreshold(jww.LevelWarn)
	}

	if Verbose {
		jww.SetLogThreshold(jww.LevelTrace)
		jww.SetStdoutThreshold(jww.LevelTrace)
	}

}
开发者ID:kadel,项目名称:grasshopper,代码行数:27,代码来源:grasshopper.go


示例6: main

func main() {
	mainCmd.AddCommand(versionCmd)
	mainCmd.AddCommand(generateCmd)
	mainCmd.AddCommand(transactCmd)
	mainCmd.AddCommand(logCmd)
	mainCmd.AddCommand(httpCmd)
	mainCmd.AddCommand(domainsCmd)

	viper.SetEnvPrefix("ORIGINS")
	viper.AutomaticEnv()

	// Default locations for the origins config file.
	viper.SetConfigName("origins")

	// Directory the program is being called from
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))

	if err == nil {
		viper.AddConfigPath(dir)
	}

	flags := mainCmd.PersistentFlags()

	flags.String("log", "info", "Level of log messages to emit. Choices are: debug, info, warn, error, fatal, panic.")
	flags.String("config", "", "Path to config file. Defaults to a origins.{json,yml,yaml} in the current working directory.")

	viper.BindPFlag("log", flags.Lookup("log"))
	viper.BindPFlag("config", flags.Lookup("config"))

	// If the target subcommand is generate, remove the generator
	// arguments to prevent flag parsing errors.
	args := parseGenerateArgs(os.Args[1:])

	// Set explicit arguments and parse the flags to setup
	// the config file and logging.
	mainCmd.SetArgs(args)
	mainCmd.ParseFlags(args)

	config := viper.GetString("config")

	if config != "" {
		viper.SetConfigFile(config)
	}

	// Read configuration file if present.
	viper.ReadInConfig()

	// Turn on debugging for all commands.
	level, err := logrus.ParseLevel(viper.GetString("log"))

	if err != nil {
		fmt.Println("Invalid log level choice.")
		mainCmd.Help()
	}

	logrus.SetLevel(level)

	mainCmd.Execute()
}
开发者ID:glycerine,项目名称:origins,代码行数:59,代码来源:main.go


示例7: init

func init() {
	serverCmd.Flags().Int("serverPort", 7767, "Port to run the REST server on")
	serverCmd.Flags().String("serverUsername", "", "HTTP Basic auth username that the REST server will require")
	serverCmd.Flags().String("serverPassword", "", "HTTP Basic auth password that the REST server will require")
	viper.BindPFlag("server.port", serverCmd.Flags().Lookup("serverPort"))
	viper.BindPFlag("server.username", serverCmd.Flags().Lookup("serverUsername"))
	viper.BindPFlag("server.password", serverCmd.Flags().Lookup("serverPassword"))
}
开发者ID:joshproehl,项目名称:minecontrol,代码行数:8,代码来源:server.go


示例8: init

func init() {
	flags := httpCmd.Flags()

	flags.String("host", "127.0.0.1", "Host of the HTTP server.")
	flags.Int("port", 7000, "Port of the HTTP server.")

	viper.BindPFlag("http.host", flags.Lookup("host"))
	viper.BindPFlag("http.port", flags.Lookup("port"))
}
开发者ID:chop-dbhi,项目名称:bitindex,代码行数:9,代码来源:http.go


示例9: init

func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.rcp.yaml)")

	rootCmd.PersistentFlags().IPP("bind", "b", net.IPv4(127, 0, 0, 1), "IP address to bind to")
	viper.BindPFlag("bind", rootCmd.PersistentFlags().Lookup("bind"))

	rootCmd.PersistentFlags().IntP("port", "p", 6379, "Port to listen on")
	viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port"))
}
开发者ID:Luit,项目名称:rcp,代码行数:10,代码来源:root.go


示例10: init

// init prepares cobra flags
func init() {
	cobra.OnInitialize(initConfig)

	Promu.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is ./.promu.yml)")
	Promu.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
	Promu.PersistentFlags().BoolVar(&useViper, "viper", true, "Use Viper for configuration")

	viper.BindPFlag("useViper", Promu.PersistentFlags().Lookup("viper"))
	viper.BindPFlag("verbose", Promu.PersistentFlags().Lookup("verbose"))
}
开发者ID:sdurrheimer,项目名称:promu,代码行数:11,代码来源:promu.go


示例11: init

func init() {
	cobra.OnInitialize(initConfig)

	RootCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is $CWD/config.yaml)")
	RootCmd.PersistentFlags().StringP("address", "a", ":9000", "address to listen to")
	RootCmd.PersistentFlags().StringP("docker-endpoint", "d", "unix:///var/run/docker.sock", "docker host endpoint")

	// Bind viper to these flags so viper can read flag values along with config, env, etc.
	viper.BindPFlag("address", RootCmd.PersistentFlags().Lookup("address"))
	viper.BindPFlag("docker-endpoint", RootCmd.PersistentFlags().Lookup("docker-endpoint"))
}
开发者ID:morfeo8marc,项目名称:docker-multi-tenancy,代码行数:11,代码来源:main.go


示例12: init

func init() {
	dlCmd.Flags().StringP("languages", "l", "en", "Languages of the subtitle separate by a comma (First to match is downloaded). Available languages at 'subify list languages'")
	dlCmd.Flags().StringP("apis", "a", "SubDB,OpenSubtitles", "Overwrite default searching APIs behavior, hence the subtitles are downloaded. Available APIs at 'subify list apis'")
	dlCmd.Flags().BoolVarP(&openVideo, "open", "o", false,
		"Once the subtitle is downloaded, open the video with your default video player"+
			` (OSX: "open", Windows: "start", Linux/Other: "xdg-open")`)
	viper.BindPFlag("download.languages", dlCmd.Flags().Lookup("languages"))
	viper.BindPFlag("download.apis", dlCmd.Flags().Lookup("apis"))

	RootCmd.AddCommand(dlCmd)
}
开发者ID:matcornic,项目名称:subify,代码行数:11,代码来源:dl.go


示例13: init

func init() {
	flags := mainCmd.PersistentFlags()

	flags.Bool("prof", false, "Enable profiling.")
	flags.String("prof-path", "./prof", "The path to store output profiles.")
	flags.Float32("smallest-threshold", 0.6, "The ratio of the set size for the complement to be returned.")

	viper.BindPFlag("main.prof", flags.Lookup("prof"))
	viper.BindPFlag("main.prof-path", flags.Lookup("prof-path"))
	viper.BindPFlag("main.smallest-threshold", flags.Lookup("smallest-threshold"))
}
开发者ID:chop-dbhi,项目名称:bitindex,代码行数:11,代码来源:main.go


示例14: init

func init() {
	flags := httpCmd.Flags()

	addStorageFlags(flags)

	flags.String("host", "", "The host the HTTP service will listen on.")
	flags.Int("port", 49110, "The port the HTTP will bind to.")

	viper.BindPFlag("http_host", flags.Lookup("host"))
	viper.BindPFlag("http_port", flags.Lookup("port"))
}
开发者ID:l-k-,项目名称:origins,代码行数:11,代码来源:http.go


示例15: init

func init() {
	RootCmd.AddCommand(routerCmd)
	routerCmd.Flags().String("server-address", "0.0.0.0", "The IP address to listen for communication")
	routerCmd.Flags().String("server-address-announce", "localhost", "The public IP address to announce")
	routerCmd.Flags().Int("server-port", 1901, "The port for communication")
	routerCmd.Flags().Bool("skip-verify-gateway-token", false, "Skip verification of the gateway token")
	viper.BindPFlag("router.server-address", routerCmd.Flags().Lookup("server-address"))
	viper.BindPFlag("router.server-address-announce", routerCmd.Flags().Lookup("server-address-announce"))
	viper.BindPFlag("router.server-port", routerCmd.Flags().Lookup("server-port"))
	viper.BindPFlag("router.skip-verify-gateway-token", routerCmd.Flags().Lookup("skip-verify-gateway-token"))
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:11,代码来源:router.go


示例16: init

func init() {
	flags := generateCmd.Flags()

	flags.String("domain", "", "Default domain to set on the facts.")
	flags.String("time", "", "The time the facts are true.")
	flags.String("operation", "", "The operation to apply to the facts, assert or retract.")

	viper.BindPFlag("generate_domain", flags.Lookup("domain"))
	viper.BindPFlag("generate_time", flags.Lookup("time"))
	viper.BindPFlag("generate_operation", flags.Lookup("operation"))
}
开发者ID:glycerine,项目名称:origins,代码行数:11,代码来源:generate.go


示例17: init

func init() {
	cobra.OnInitialize(initConfig)
	// Default configuration can be overridden
	RootCmd.PersistentFlags().StringVar(&config.ConfigFile, "config", "",
		"Config file (default is $HOME/.subify.yaml|json|toml). Edit to change default behavior")
	RootCmd.PersistentFlags().BoolVarP(&config.Verbose, "verbose", "v", false,
		"Print more information while executing")
	RootCmd.PersistentFlags().BoolVarP(&config.Dev, "dev", "", false,
		"Instanciate development sandbox instead of production variables")
	viper.BindPFlag("root.dev", RootCmd.PersistentFlags().Lookup("dev"))
	viper.BindPFlag("root.verbose", RootCmd.PersistentFlags().Lookup("verbose"))
}
开发者ID:matcornic,项目名称:subify,代码行数:12,代码来源:root.go


示例18: init

func init() {
	RootCmd.AddCommand(createUserCmd)

	// @NOTE: Do not set the default values here, that doesn't work correctly!
	createUserCmd.Flags().StringP("name", "n", "", "username")
	createUserCmd.Flags().StringP("hmackey", "p", "", "hmackey")

	viper.BindPFlag("name", createUserCmd.Flags().Lookup("name"))
	viper.BindPFlag("hmackey", createUserCmd.Flags().Lookup("hmackey"))

	viper.SetDefault("hmackey", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
}
开发者ID:lstep,项目名称:2fanginx,代码行数:12,代码来源:createuser.go


示例19: init

func init() {
	cobra.OnInitialize(initConfig)
	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
	RootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "", "base project directory, e.g. github.com/spf13/")
	RootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "Author name for copyright attribution")
	RootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "Name of license for the project (can provide `license` in config)")
	RootCmd.PersistentFlags().Bool("viper", true, "Use Viper for configuration")
	viper.BindPFlag("author", RootCmd.PersistentFlags().Lookup("author"))
	viper.BindPFlag("projectbase", RootCmd.PersistentFlags().Lookup("projectbase"))
	viper.BindPFlag("useViper", RootCmd.PersistentFlags().Lookup("viper"))
	viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
	viper.SetDefault("license", "apache")
}
开发者ID:ContiGuy,项目名称:conti-gui,代码行数:13,代码来源:root.go


示例20: init

func init() {
	flags := httpCmd.Flags()

	addStorageFlags(flags)

	flags.String("host", "", "The host the HTTP service will listen on.")
	flags.Int("port", 49110, "The port the HTTP will bind to.")
	flags.String("allowed-hosts", "*", "Set of allowed hosts for cross-origin resource sharing.")

	viper.BindPFlag("http_host", flags.Lookup("host"))
	viper.BindPFlag("http_port", flags.Lookup("port"))
	viper.BindPFlag("http_allowed_hosts", flags.Lookup("allowed-hosts"))
}
开发者ID:glycerine,项目名称:origins,代码行数:13,代码来源:http.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang viper.BindPFlags函数代码示例发布时间:2022-05-28
下一篇:
Golang viper.BindEnv函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap