本文整理汇总了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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng