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

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

示例1: init

//####################################//
// Code
//====================================//
// Init code
func init() {
    // FIXME init flags
    const (
        flagDef_Debug = false
        flagDescDebug = "   -debug   enable debug"
        flagDef_Quiet = false
        flagDescQuiet = "-q -quiet   suppress output"
    )
    flag.BoolVar(&flagDebug, "debug", false, flagDescDebug)
    flag.BoolVar(&flagQuiet, "q", false, flagDescQuiet)
    flag.BoolVar(&flagQuiet, "quiet", false, flagDescQuiet)

    //----------------------------------//
    // Help
    // FIXME update help
    flag.Usage = func() {
        usage := `Usage: %s [options]
Options:
  ` + flag.Lookup("q").Usage + `
  ` + flag.Lookup("debug").Usage + `
  No more options for now.

MIT, BSD or something. There is no help.
`
        fmt.Fprintf(os.Stderr, usage, os.Args[0])
    }
    //----------------------------------//
}

开发者ID:Tracerneo,项目名称:WebServerTemplate,代码行数:32,代码来源:main.go

示例2: TestRegisterFlags

func TestRegisterFlags(t *testing.T) {
    c := &Config{
        DHTRouters:    "example.router.com:6060",
        MaxNodes:      2020,
        CleanupPeriod: time.Second,
        SavePeriod:    time.Second * 2,
        RateLimit:     999,
    }
    RegisterFlags(c)
    if flag.Lookup("routers").DefValue != c.DHTRouters {
        t.Fatal("Incorrect routers flag")
    }
    if flag.Lookup("maxNodes").DefValue != strconv.FormatInt(int64(c.MaxNodes), 10) {
        t.Fatal("Incorrect maxNodes flag")
    }
    if flag.Lookup("cleanupPeriod").DefValue != c.CleanupPeriod.String() {
        t.Fatal("Incorrect cleanupPeriod flag")
    }
    if flag.Lookup("savePeriod").DefValue != c.SavePeriod.String() {
        t.Fatal("Incorrect routers flag")
    }
    if flag.Lookup("rateLimit").DefValue != strconv.FormatInt(c.RateLimit, 10) {
        t.Fatal("Incorrect routers flag")
    }
}

开发者ID:peterlee2008,项目名称:dht,代码行数:25,代码来源:dht_test.go

示例3: main

func main() {
    flag.Parse()

    if *cliVersion {
        fmt.Println(flag.Lookup("version").Usage)
        exit(0)
        return
    }
    if *cliHelp {
        fmt.Println(flag.Lookup("help").Usage)
        exit(0)
        return
    }
    var res beatsone.BeatsOne
    var err error
    if *cliSchedule {
        res, err = beatsone.GetSchedule()
    } else {
        res, err = beatsone.GetNowPlaying()
    }
    if err != nil {
        fmt.Println(err)
        exit(1)
    }
    if *cliJSON {
        fmt.Println(res.JSONString())
    } else {
        fmt.Println(res.String())
    }
    exit(0)
    return
}

开发者ID:hygerth,项目名称:beatsone,代码行数:32,代码来源:main.go

示例4: Setup

func (p *GitParser) Setup() {
    executable := flag.Lookup("executable").Value.String()
    out := flag.Lookup("out").Value.String()

    if out == "<STDOUT>" {
        out = "REVISION.json"
    }

    hook := executable + " -out=\"" + out + "\"; # scm-status hook\r\n"

    hook_dir := strings.Join([]string{p.Dir(), ".git", "hooks"}, path_separator)

    filenames := []string{
        hook_dir + path_separator + "post-checkout",
        hook_dir + path_separator + "post-merge",
        hook_dir + path_separator + "post-commit",
    }

    for _, filename := range filenames {
        fp, _ := os.OpenFile(filename, os.O_RDWR+os.O_APPEND+os.O_CREATE, 0775)

        _, _ = fp.WriteString(hook)

        fp.Close()
    }
}

开发者ID:jimmysawczuk,项目名称:scm-status,代码行数:26,代码来源:git.go

示例5: main

func main() {
    flag.Parse()

    if flagOne == "" {
        fmt.Fprintf(os.Stdout, "Usage of cody.guo ok %s:\n", os.Args[0])
        flag.PrintDefaults()
        os.Exit(1)
    }

    fmt.Println("参数数量:", flag.NFlag())
    oneFlag := flag.Lookup("one")

    fmt.Println(oneFlag.Name, oneFlag.Value)

    // fmt.Println(len(os.Args))

    if debug {
        fmt.Println("debug is on.")
    } else {
        fmt.Println("debug is off.")
    }

    fmt.Println(flagOne)

    debugFlag := flag.Lookup("d")
    fmt.Println(debugFlag.Name, debugFlag.Value)

}

开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:28,代码来源:main.go

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