本文整理汇总了Golang中flag.VisitAll函数的典型用法代码示例。如果您正苦于以下问题:Golang VisitAll函数的具体用法?Golang VisitAll怎么用?Golang VisitAll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VisitAll函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pretty_print_flags
func pretty_print_flags(prefix string, detail bool) {
if detail {
max1 := 0
max2 := 0
flag.VisitAll(func(f *flag.Flag) {
len1 := len(f.Name)
len2 := len(fmt.Sprintf("%v", f.Value))
if max1 < len1 {
max1 = len1
}
if max2 < len2 {
max2 = len2
}
})
format := fmt.Sprintf(" --%%-%ds %%%dv %%s\n", max1, max2)
format = "%s" + format
flag.VisitAll(func(f *flag.Flag) {
fmt.Printf(format, prefix, f.Name, f.Value, f.Usage)
})
} else {
flag.VisitAll(func(f *flag.Flag) {
fmt.Printf("%s--%s=%v\n", prefix, f.Name, f.Value)
})
}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:32,代码来源:example.go
示例2: usage
// Prints the usage of the Iris command and its options.
func usage() {
fmt.Printf("Server node of the Iris decentralized messaging framework.\n\n")
fmt.Printf("Usage:\n\n")
fmt.Printf("\t%s [options]\n\n", os.Args[0])
fmt.Printf("The options are:\n\n")
flag.VisitAll(func(f *flag.Flag) {
if !strings.HasSuffix(f.Name, "prof") {
if f.DefValue != "" {
fmt.Printf("\t-%-8s%-12s%s\n", f.Name, "[="+f.DefValue+"]", f.Usage)
} else {
fmt.Printf("\t-%-20s%s\n", f.Name, f.Usage)
}
}
})
fmt.Printf("\n")
fmt.Printf("Profiling options:\n\n")
flag.VisitAll(func(f *flag.Flag) {
if strings.HasSuffix(f.Name, "prof") {
fmt.Printf("\t-%-20s%s\n", f.Name, f.Usage)
}
})
fmt.Printf("\n")
}
开发者ID:ibmendoza,项目名称:iris-0.3.2,代码行数:26,代码来源:main.go
示例3: saveConfig
func saveConfig(w io.Writer, obsKeys map[string]string) {
// find flags pointing to the same variable. We will only write the longest
// named flag to the config file, the shorthand version is ignored.
deduped := make(map[flag.Value]flag.Flag)
flag.VisitAll(func(f *flag.Flag) {
if cur, ok := deduped[f.Value]; !ok || utf8.RuneCountInString(f.Name) > utf8.RuneCountInString(cur.Name) {
deduped[f.Value] = *f
}
})
flag.VisitAll(func(f *flag.Flag) {
if cur, ok := deduped[f.Value]; ok && cur.Name == f.Name {
_, usage := flag.UnquoteUsage(f)
usage = strings.Replace(usage, "\n \t", "\n# ", -1)
fmt.Fprintf(w, "\n# %s (default %v)\n", usage, f.DefValue)
fmt.Fprintf(w, "%s=%v\n", f.Name, f.Value.String())
}
})
// if we have obsolete keys left from the old config, preserve them in an
// additional section at the end of the file
if obsKeys != nil && len(obsKeys) > 0 {
fmt.Fprintln(w, "\n\n# The following options are probably deprecated and not used currently!")
for key, val := range obsKeys {
fmt.Fprintf(w, "%v=%v\n", key, val)
}
}
}
开发者ID:schachmat,项目名称:ingo,代码行数:27,代码来源:in.go
示例4: FlagParse
func FlagParse(positional string, desc string) {
for _, fl := range commonFlags {
if fl.use {
fl.set()
}
}
flag.Usage = func() {
log.Printf("Usage: %s [flags] %s\n\n",
path.Base(os.Args[0]), positional)
if len(desc) > 0 {
log.Printf("%s\n\n", desc)
}
flag.VisitAll(func(fl *flag.Flag) {
var def string
if len(fl.DefValue) > 0 {
def = fmt.Sprintf(" (default: %s)", fl.DefValue)
}
usage := strings.Replace(fl.Usage, "\n", "\n ", -1)
log.Printf("-%s%s\n", fl.Name, def)
log.Printf(" %s\n", usage)
})
os.Exit(1)
}
flag.Parse()
for _, fl := range commonFlags {
if fl.use && fl.init != nil {
fl.init()
}
}
}
开发者ID:ndaniels,项目名称:tools,代码行数:33,代码来源:flags.go
示例5: Usage
// Usage prints the usage information for the application including all flags
// and their values after parsing the configuration file
func Usage() {
Parse()
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(os.Stderr, " -%s=%s: %s\n", f.Name, f.Value.String(), f.Usage)
})
}
开发者ID:facebookgo,项目名称:flagconfig,代码行数:9,代码来源:flagconfig.go
示例6: Parse
func Parse() {
if *configFile == "" {
return
}
config := readConfig()
explicit := make([]*flag.Flag, 0)
all := make([]*flag.Flag, 0)
flag.Visit(func(f *flag.Flag) {
explicit = append(explicit, f)
})
flag.VisitAll(func(f *flag.Flag) {
all = append(all, f)
if !contains(explicit, f) {
val := config[f.Name]
if val != "" {
err := f.Value.Set(val)
if err != nil {
log.Fatalf("Failed to set flag %s with value %s", f.Name, val)
}
}
}
})
Outer:
for name, val := range config {
for _, f := range all {
if f.Name == name {
continue Outer
}
}
log.Fatalf("Unknown flag %s=%s in config file.", name, val)
}
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:32,代码来源:flagconfig.go
示例7: parse
func parse() (err error) {
// Record which flags were set by command line args so that we don't overwrite them.
set := make(map[*flag.Flag]bool, 0)
flag.Visit(func(f *flag.Flag) {
set[f] = true
})
flag.VisitAll(func(f *flag.Flag) {
if !set[f] && err == nil {
r := strings.NewReplacer(".", "_", "-", "_")
name := r.Replace(f.Name)
if UseUpperCaseFlagNames {
name = strings.ToUpper(name)
}
val := os.Getenv(name)
if val != "" {
if seterr := f.Value.Set(val); seterr != nil {
err = fmt.Errorf("Failed to set flag %s with value %s", f.Name, val)
}
}
}
})
return
}
开发者ID:josharian,项目名称:go.flagenv,代码行数:25,代码来源:flagenv.go
示例8: init
func init() {
flag.Parse()
// Create a map of pointers to all the current flags
flags := map[string]*flag.Flag{}
flag.VisitAll(func(f *flag.Flag) {
flags[f.Name] = f
})
// Remove the flags that were set on the command line
flag.Visit(func(f *flag.Flag) {
delete(flags, f.Name)
})
// Now for the flags that weren't set on the cli,
// Look at the env for 'PBOX_<uppercase flag name>'
// If it exists, use it to set the corresponding flag.
for _, f := range flags {
var buffer bytes.Buffer
buffer.WriteString("PBOX_")
buffer.WriteString(strings.ToUpper(f.Name))
if os.Getenv(buffer.String()) != "" {
f.Value.Set(os.Getenv(buffer.String()))
}
}
}
开发者ID:nickjones,项目名称:proc_box,代码行数:26,代码来源:main.go
示例9: getFlags
func getFlags() []string {
flagData := []string{}
flag.VisitAll(func(flag *flag.Flag) {
flagData = append(flagData, fmt.Sprintf("%s='%v'", flag.Name, flag.Value))
})
return flagData
}
开发者ID:DreadPirateShawn,项目名称:heapster,代码行数:7,代码来源:heapster.go
示例10: parse
// parse() iterates through the flags and populate the
// values from environment variables if present
func parse(prefix string) (errp error) {
cmdline := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
cmdline[f.Name] = true
})
flag.VisitAll(func(f *flag.Flag) {
if _, ok := cmdline[f.Name]; !ok {
val := os.Getenv(getEnvName(prefix, f.Name))
if val != "" {
err := f.Value.Set(val)
if err != nil {
if errp != nil {
errp = fmt.Errorf(errp.Error()+", value:\"%s\" for flag:\"%s\"", val, f.Name)
} else {
errp = fmt.Errorf(":envtoflag: error setting value:\"%s\" for flag:\"%s\"", val, f.Name)
}
}
}
}
})
return
}
开发者ID:PayPal-OpportunityHack-BLR-2015,项目名称:bloodcare-hifx,代码行数:28,代码来源:envtoflag.go
示例11: main
func main() {
flag.Parse()
flag.VisitAll(func(f *flag.Flag) {
if fmt.Sprintf("%s", f.Value) == f.DefValue {
log.Println("Arguments invalid")
os.Exit(0)
}
})
absRoot, err := filepath.Abs(*root)
if err != nil {
log.Fatal(err)
}
absKey, err := filepath.Abs(*keyFile)
if err != nil {
log.Fatal(err)
}
absCert, err := filepath.Abs(*certFile)
if err != nil {
log.Fatal(err)
}
secret := auth.HtdigestFileProvider(*htdigest)
authenticator := auth.NewDigestAuthenticator(*realm, secret)
log.Printf("Starting server on port %d\n", *port)
hostport := fmt.Sprintf(":%d", *port)
authHandler := makeAuthHandler(http.FileServer(http.Dir(absRoot)))
handler := authenticator.Wrap(authHandler)
log.Fatal(http.ListenAndServeTLS(hostport, absCert, absKey, handler))
}
开发者ID:shaladdle,项目名称:fileserver,代码行数:35,代码来源:fileserver.go
示例12: dumpFlags
func dumpFlags() {
flag.VisitAll(func(f *flag.Flag) {
if f.Name != "config" && f.Name != "dumpflags" {
fmt.Printf("%s = %s # %s\n", f.Name, quoteValue(f.Value.String()), escapeUsage(f.Usage))
}
})
}
开发者ID:bertbaron,项目名称:iniflags,代码行数:7,代码来源:iniflags.go
示例13: main
func main() {
flag.Parse()
flag.VisitAll(func(f *flag.Flag) {
fmt.Printf("%s=%v\n", f.Name, f.Value)
})
runtime.GOMAXPROCS(*goMaxProcs)
victimUri, err := url.Parse(*victimUrl)
if err != nil {
log.Fatalf("Cannot parse victimUrl=[%s]: [%s]\n", victimUrl, err)
}
victimHostPort := victimUri.Host
if !strings.Contains(victimHostPort, ":") {
port := "80"
if victimUri.Scheme == "https" {
port = "443"
}
victimHostPort = net.JoinHostPort(victimHostPort, port)
}
requestHeader := []byte(fmt.Sprintf("POST %s HTTP/1.1\nHost: %s\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n",
victimUri.RequestURI(), victimUri.Host, *contentLength))
dialWorkersLaunchInterval := *rampUpInterval / time.Duration(*dialWorkersCount)
activeConnectionsCh := make(chan int, *dialWorkersCount)
go activeConnectionsCounter(activeConnectionsCh)
for i := 0; i < *dialWorkersCount; i++ {
go dialWorker(activeConnectionsCh, victimHostPort, victimUri, requestHeader)
time.Sleep(dialWorkersLaunchInterval)
}
time.Sleep(*testDuration)
}
开发者ID:gasperko,项目名称:goloris,代码行数:32,代码来源:goloris.go
示例14: numFlags
// Returns the number of flags that have been declared.
func numFlags() int {
n := 0
flag.VisitAll(func(f *flag.Flag) {
n++
})
return n
}
开发者ID:rkoesters,项目名称:goblin,代码行数:8,代码来源:flagutil.go
示例15: GetUsage
func (l *Layout) GetUsage(app, desc, ver string) func() {
return func() {
fmt.Printf("NAME: \t %v - %v\n", l.bash.Blue(app), l.bash.White(desc))
//fmt.Printf("%v", l.bash.Blue(fmt.Sprintf("\n\t\t### %v - %v ###\n\n", app, desc)))
fmt.Printf("USAGE:\t %v %v\n", l.bash.Blue(path.Base(os.Args[0])), l.bash.White("[arguments...]"))
fmt.Printf("VER: \t %v\n", l.bash.Blue(ver))
fmt.Println("COMMANDS:")
flag.VisitAll(func(f *flag.Flag) {
extra := (func(extra string) string {
if len(extra) == 0 {
return ""
}
return fmt.Sprintf("[default: %v]", l.bash.White(extra))
})(f.DefValue)
space := "\t%v: \t %v %v \n"
if len(f.Name) < 7 {
space = "\t%v: \t\t %v %v \n"
} else if len(f.Name) < 3 {
space = "\t%v: +\t\t\t %v %v \n"
}
fmt.Printf(space, l.bash.Green(f.Name), l.bash.Yellow(f.Usage), extra)
})
}
}
开发者ID:rodkranz,项目名称:ff,代码行数:28,代码来源:layout.go
示例16: printFlags
func printFlags() {
var s []string
flag.VisitAll(func(fl *flag.Flag) {
s = append(s, "-"+fl.Name)
})
fmt.Printf("%v", strings.Join(s, " "))
}
开发者ID:otm,项目名称:blade,代码行数:7,代码来源:compgen.go
示例17: getMissingFlags
func getMissingFlags() []string {
var (
set, missing []string
found = false
)
// Visit only the flags that have been set
flag.Visit(func(f *flag.Flag) {
set = append(set, f.Name)
})
// Visit all the flags, even those not set
flag.VisitAll(func(f *flag.Flag) {
for _, v := range set {
if v == f.Name {
found = true
break
}
}
// If we don't find the flag in the slice of already set flags, we add it to the missing slice
if !found {
missing = append(missing, f.Name)
}
found = false
})
return missing
}
开发者ID:vaz-ar,项目名称:cfgFlags,代码行数:25,代码来源:cfgFlags.go
示例18: usageMsg
func usageMsg() {
fmt.Fprintln(os.Stderr, msg)
off := 0
flag.VisitAll(func(f *flag.Flag) {
if off < len(f.Name) {
off = len(f.Name)
}
})
flag.VisitAll(func(f *flag.Flag) {
sep := make([]byte, off-len(f.Name))
for i := range sep {
sep[i] = 0x20
}
fmt.Fprintf(os.Stderr, "-%s %s-- %s\n", f.Name, sep, f.Usage)
})
}
开发者ID:bobappleyard,项目名称:tsi,代码行数:16,代码来源:main.go
示例19: generalHelp
func generalHelp() {
out := tabwriter.NewWriter(os.Stderr, 0, 8, 1, '\t', 0)
exe := filepath.Base(os.Args[0])
fmt.Fprintf(out, "USAGE:\n\t%s [global options] <command> [command options] [arguments...]\n\n", exe)
fmt.Fprintf(out, "VERSION:\n\t%s\n\n", Version)
fmt.Fprintf(out, "COMMANDS:\n")
names := sort.StringSlice{}
for name, _ := range subcommands {
names = append(names, name)
}
names.Sort()
for _, name := range names {
cmd := subcommands[name]
fmt.Fprintf(out, "\t%s\t%s\n", name, cmd.desc())
}
fmt.Fprintln(out)
fmt.Fprintf(out, "GLOBAL OPTIONS:\n")
flag.VisitAll(func(f *flag.Flag) {
prefix := "-"
if len(f.Name) > 1 {
prefix = "--"
}
fmt.Fprintf(out, "\t%s%s=%s\t%s\n", prefix, f.Name, f.DefValue, f.Usage)
})
fmt.Fprintln(out)
fmt.Fprintf(out, "Run \"%s help <command>\" for more details about a command.\n", exe)
}
开发者ID:logan,项目名称:heim,代码行数:30,代码来源:subcommands.go
示例20: main
func main() {
log.SetFlags(log.Flags() | log.Llongfile)
//recv := &chromebus.ChromebusRecordStdinReceiver{}
//str, _ := recv.GetRecord()
//log.Printf("%s", str)
//str, _ = recv.GetRecord()
//log.Printf("%s", str)
flag.Parse()
flag.VisitAll(defFlags)
if !serverMode {
chromebus.EnvSetup()
}
var e *chromebus.Engine
if pluginsDefined {
e = chromebus.CreateEngine(plugins, port)
} else {
e = chromebus.CreateEngine(nil, port)
}
go func() {
e.Start()
}()
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt, os.Kill)
<-signalChannel
e.CleanUp()
//rcv := ChromebusRecordStdinReceiver{}
//exec.Command("date")
}
开发者ID:washtubs,项目名称:chromebus,代码行数:30,代码来源:main.go
注:本文中的flag.VisitAll函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论