本文整理汇总了Golang中github.com/spf13/cobra.OnInitialize函数的典型用法代码示例。如果您正苦于以下问题:Golang OnInitialize函数的具体用法?Golang OnInitialize怎么用?Golang OnInitialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OnInitialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default $HOME/.lateral/config.yaml)")
RootCmd.PersistentFlags().StringP("socket", "s", "", "UNIX domain socket path (default $HOME/.lateral/socket.$SESSIONID)")
Viper.BindPFlag("socket", RootCmd.PersistentFlags().Lookup("socket"))
}
示例2: init
func init() {
cobra.OnInitialize(initConfig)
// Setting flags here so they can be used by both the root behavior as well as
// by the indidual behaviors of icarus and daedalus
RootCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is $CWD/config.yaml)")
RootCmd.PersistentFlags().IntP("port", "p", 8013, "Port run on")
RootCmd.PersistentFlags().IntP("width", "x", 15, "width of the laybrinth")
RootCmd.PersistentFlags().IntP("height", "y", 10, "height of the laybrinth") // 'h' is used for help already
RootCmd.PersistentFlags().IntP("times", "t", 1, "times to solve the laybrinth")
RootCmd.PersistentFlags().IntP("max-steps", "m", 500, "Maximum steps before giving up")
RootCmd.PersistentFlags().Bool("mouse", false, "Use random mouse solver")
RootCmd.PersistentFlags().String("bias", "O", "Bias for maze generator. H,V,X,O or D")
// Bind viper to these flags so viper can read flag values along with config, env, etc.
viper.BindPFlag("width", RootCmd.PersistentFlags().Lookup("width"))
viper.BindPFlag("height", RootCmd.PersistentFlags().Lookup("height"))
viper.BindPFlag("port", RootCmd.PersistentFlags().Lookup("port"))
viper.BindPFlag("times", RootCmd.PersistentFlags().Lookup("times"))
viper.BindPFlag("max-steps", RootCmd.PersistentFlags().Lookup("max-steps"))
viper.BindPFlag("mouse", RootCmd.PersistentFlags().Lookup("mouse"))
viper.BindPFlag("bias", RootCmd.PersistentFlags().Lookup("bias"))
}
示例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/.alea.yaml)")
RootCmd.PersistentFlags().StringVar(&cfg.controller, "controller", "", "alea controller URL, set it manually if it can't be resolved from the deis git remote, defaults to services.<deis.domain>")
RootCmd.Flags().StringVarP(&cfg.app, "app", "a", "", "deis app name, set it manually if it can't be resolved from the deis git remote")
// Cobra also supports local flags, which will only run
// when this action is called directly.
// RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
if cfg.app == "" {
app, err := git.GetAppFromRemote()
if err != nil {
fmt.Println("Could not get App from git remote\n\nRun this command from the root of your Deis app for best results or pass in -a <app-name>\n\n")
}
cfg.app = app
}
}
示例4: init
func init() {
cobra.OnInitialize(initConfig)
// Command flags
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.goigc.yaml)")
}
示例5: init
func init() {
cobra.OnInitialize(initConfig)
// Setup logging for the package. Doing it here is much eaiser than in each
// binary. If you want to overwrite it in a specific binary then feel free.
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
if err != nil {
panic(err)
}
syslogLog.Hooks.Add(hook)
syslogLog.Formatter = new(logrus.JSONFormatter)
// Set the hostname for use in logging within the package. Doing it here is
// cleaner than in each binary but if you want to use some other method just
// override the variable in the specific binary.
host, err = os.Hostname()
if err != nil {
syslogLog.WithFields(logrus.Fields{
"check": "sensupluginses",
"client": "unknown",
"version": version.AppVersion(),
"error": err,
}).Error(`Could not determine the hostname of this machine as reported by the kernel.`)
sensuutil.Exit("GENERALGOLANGERROR")
}
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sensupluginses.yaml)")
RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
示例6: init
func init() {
credential = common.NewCredentialCobra(RootCmd)
cli.OnInitialize(initConfig)
RootCmd.AddCommand(hostCmd)
RootCmd.AddCommand(tenantCmd)
RootCmd.AddCommand(segmentCmd)
RootCmd.AddCommand(policyCmd)
RootCmd.Flags().BoolVarP(&version, "version", "",
false, "Build and Versioning Information.")
RootCmd.PersistentFlags().StringVarP(&cfgFile, "config",
"c", "", "config file (default is $HOME/.romana.yaml)")
RootCmd.PersistentFlags().StringVarP(&rootURL, "rootURL",
"r", "", "root service url, e.g. http://192.168.0.1")
RootCmd.PersistentFlags().StringVarP(&rootPort, "rootPort",
"p", "", "root service port, e.g. 9600")
RootCmd.PersistentFlags().StringVarP(&format, "format",
"f", "", "enable formatting options like [json|table], etc.")
RootCmd.PersistentFlags().StringVarP(&platform, "platform",
"P", "", "Use platforms like [openstack|kubernetes], etc.")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose",
"v", false, "Verbose output.")
RootCmd.PersistentPreRun = preConfig
RootCmd.Run = versionInfo
}
示例7: init
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.runes.yaml)")
RootCmd.AddCommand(createCmd)
RootCmd.AddCommand(runCmd)
}
示例8: 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)
}
示例9: 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/.gopixabay.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
RootCmd.PersistentFlags().StringVarP(&arguments.request.Key, "key", "k", "", "Your pixabay API key")
RootCmd.Flags().StringVarP(&arguments.request.ResponseGroup, "response-group", "g", "image_details", "Select the information returned: image details or URLs of high resolution images. High resolution image URLs and details cannot be obtained in a single request. (image_details, high_resolution)")
RootCmd.Flags().StringVar(&arguments.request.ID, "id", "", "ID, ID hash, or a comma separated list of values for fetching or updating specific images. In a comma separated list, IDs and ID hashs cannot be used together.")
RootCmd.Flags().StringVarP(&arguments.request.Query, "query", "q", "", "A text query to use when searching for images")
RootCmd.Flags().StringVarP(&arguments.request.Lang, "lang", "l", "en", "Language code of the language to be searched in. ")
RootCmd.Flags().StringVarP(&arguments.request.ImageType, "image-type", "t", "all", "A media type to search within. (all, photo, illustration, vector)")
RootCmd.Flags().StringVarP(&arguments.request.Orientation, "orientation", "o", "all", "Whether an image is wider than it is tall, or taller than it is wide. (all, horizontal, vertical)")
RootCmd.Flags().StringVarP(&arguments.request.Category, "category", "c", "", "Filter images by category. (fashion, nature, backgrounds, science, education, people, feelings, religion, health, places, animals, industry, food, computer, sports, transportation, travel, buildings, business, music)")
RootCmd.Flags().IntVar(&arguments.request.MinWidth, "min-width", 0, "Minimum image width. ")
RootCmd.Flags().IntVar(&arguments.request.MinWidth, "min-height", 0, "Minimum image height. ")
RootCmd.Flags().BoolVarP(&arguments.request.EditorsChoice, "editors-choice", "e", false, "Select images that have received an Editor's Choice award. ")
RootCmd.Flags().BoolVarP(&arguments.request.SafeSearch, "safesearch", "s", false, "A flag indicating that only images suitable for all ages should be returned. ")
RootCmd.Flags().StringVarP(&arguments.request.Order, "order", "r", "popular", "How the results should be ordered. (popular, latest)")
RootCmd.Flags().IntVarP(&arguments.request.Page, "page", "p", 1, "Returned search results are paginated. Use this parameter to select the page number. ")
RootCmd.Flags().IntVar(&arguments.request.PerPage, "per-page", 20, "Determine the number of results per page.")
RootCmd.Flags().StringVar(&arguments.request.Callback, "callback", "", "JSONP callback function name")
RootCmd.Flags().BoolVar(&arguments.request.Pretty, "pretty", false, "Prettify and indent JSON output. This option is for development puposes only and should not be used in production. ")
RootCmd.Flags().StringVar(&arguments.size, "size", "og", "Image size to download (og, lg, md, sm, xs) ")
RootCmd.Flags().IntVar(&arguments.simultaneous, "num", 4, "Number of images to download in paralell")
}
示例10: 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.
`)
}
示例11: init
func init() {
cobra.OnInitialize(initConfig)
// Setting flags here so they can be used by both the root behavior as well as
// by the indidual behaviors of icarus and daedalus
RootCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is $CWD/config.yaml)")
RootCmd.PersistentFlags().IntP("port", "p", 8013, "Port run on")
RootCmd.PersistentFlags().IntP("width", "x", 15, "width of the laybrinth")
RootCmd.PersistentFlags().IntP("height", "y", 10, "height of the laybrinth") // 'h' is used for help already
RootCmd.PersistentFlags().IntP("times", "t", 1, "times to solve the laybrinth")
RootCmd.PersistentFlags().IntP("max-steps", "m", 500, "Maximum steps before giving up")
RootCmd.PersistentFlags().BoolP("interactive", "i", false, "runs in interactive mode")
RootCmd.PersistentFlags().BoolP("debug", "d", false, "prints debug messages")
RootCmd.PersistentFlags().Float64P("braid", "b", 1.0, "probability to rearrange an dead end to a braid")
// Bind viper to these flags so viper can read flag values along with config, env, etc.
_ = viper.BindPFlag("width", RootCmd.PersistentFlags().Lookup("width"))
_ = viper.BindPFlag("height", RootCmd.PersistentFlags().Lookup("height"))
_ = viper.BindPFlag("port", RootCmd.PersistentFlags().Lookup("port"))
_ = viper.BindPFlag("times", RootCmd.PersistentFlags().Lookup("times"))
_ = viper.BindPFlag("max-steps", RootCmd.PersistentFlags().Lookup("max-steps"))
_ = viper.BindPFlag("interactive", RootCmd.PersistentFlags().Lookup("interactive"))
_ = viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug"))
_ = viper.BindPFlag("braid", RootCmd.PersistentFlags().Lookup("braid"))
}
示例12: init
func init() {
initFlags(cliContext)
cobra.OnInitialize(func() {
cliContext.Addr = net.JoinHostPort(connHost, connPort)
})
}
示例13: init
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
"config file path.")
RootCmd.PersistentFlags().BoolVarP(&log.ShowDebug, "debug", "d", false,
"Print debug information")
}
示例14: 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")
}
示例15: init
func init() {
flags := app.PersistentFlags()
flags.BoolVarP(&boolVerbose, "verbose", "V", false, "Print verbose messages")
flags.BoolVarP(&boolDebug, "debug", "D", false, "Print debug messages")
cobra.OnInitialize(Initialize)
}