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

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

示例1: main

func main() {
    flag.Parse()
    finished := make(chan bool)
    joblist := newJoblist(finished)

    useCmdFile := false
    useCmdPort := false
    markFlags := func(f *flag.Flag) {
        if f.Name == "cmdport" {
            useCmdPort = true
        } else if f.Name == "cmdfile" {
            useCmdFile = true
        }
    }
    flag.Visit(markFlags)

    startWorkers(joblist)

    if useCmdFile {
        postCommandsFromFile(joblist, useCmdPort)
    }
    if !useCmdFile || useCmdPort {
        go startAdders(joblist)
    }

    <-finished
    logfile.Printf("%d jobs succeeded\n", joblist.nok)
    logfile.Printf("%d jobs failed\n", joblist.nfail)
    logfile.Printf("%d jobs completed\n", joblist.nok+joblist.nfail)
}

开发者ID:velour,项目名称:distribute,代码行数:30,代码来源:main.go

示例2: 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

示例3: Save

// Save set options to a configuration file. If categories are given, only those
// options in one of the categories is saved.
func Save(path, comment string, category ...string) error {
    file, err := util.CreatePath(path, 0777, 0777)
    if err != nil {
        return err
    }
    defer file.Close()

    set := make(map[string]bool)
    flag.Visit(func(f *flag.Flag) {
        set[f.Name] = true
    })

    for _, s := range strings.Split(comment, "\n") {
        fmt.Fprintf(file, "# %s\n", s)
    }
    fmt.Fprintf(file, "# Generated on %s\n", time.Now())

    for _, opt := range Options {
        f := flag.Lookup(opt.Name)
        if !opt.Relevant(category...) || f == nil {
            continue
        }
        fmt.Fprintf(file, "\n# %s\n", opt.Help)
        if set[opt.Name] {
            fmt.Fprintf(file, "%s = %v\n", opt.Name, f.Value)
        } else {
            fmt.Fprintf(file, "# %s = %v\n", opt.Name, f.Value)
        }
    }
    return nil
}

开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:33,代码来源:options.go

示例4: 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

示例5: 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

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