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

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

示例1: main

func main() {
    // Parse the command line flags.
    hexPtr := flag.String("hex", "", "a hex value to convert to RGB")
    flag.Var(&rgbflag, "rgb", "an RGB value to convert to hex")
    flag.Parse()

    // If neither flag is provided, print usage and exit.
    if flag.NFlag() == 0 || flag.NFlag() == 2 {
        fmt.Println("Usage: rgbhex [-hex=ABCDEF | -rgb=123,234,100]")
        os.Exit(1)
    }

    if *hexPtr != "" {
        // Convert the provided hex value into an integer.
        hexVal, err := strconv.ParseInt(*hexPtr, 16, 32)
        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
        fmt.Println(HexToRGB(hexVal))
    } else {
        // Convert an RGB value to hex.
        fmt.Println(RGBToHex(&rgbflag))
    }
}

开发者ID:RocketDonkey,项目名称:random,代码行数:25,代码来源:rgbhex.go

示例2: main

func main() {
    // Arguments
    fileName := flag.String("c", "config.json", "config file")
    debug := flag.Bool("d", false, "debug mode")
    vers := flag.Bool("v", false, "version")
    flag.Parse()
    // Version
    if *vers {
        fmt.Fprintln(os.Stdout, version.Version)
        os.Exit(1)
    }
    // Logging
    log.SetName("banshee")
    if *debug {
        log.SetLevel(log.DEBUG)
    }
    log.Debug("using %s, max %d cpu", runtime.Version(), runtime.GOMAXPROCS(-1))
    // Config
    cfg := config.New()
    if flag.NFlag() == 0 || (flag.NFlag() == 1 && *debug == true) {
        log.Warn("no config file specified, using default..")
    } else {
        err := cfg.UpdateWithJSONFile(*fileName)
        if err != nil {
            log.Fatal("failed to load %s, %s", *fileName, err)
        }
    }
    // Storage
    options := &storage.Options{
        NumGrid: cfg.Period[0],
        GridLen: cfg.Period[1],
    }
    db, err := storage.Open(cfg.Storage.Path, options)
    if err != nil {
        log.Fatal("failed to open %s: %v", cfg.Storage.Path, err)
    }
    // Cleaner
    cleaner := cleaner.New(db, cfg.Period[0]*cfg.Period[1])
    go cleaner.Start()
    // Filter
    filter := filter.New()
    filter.Init(db)
    // Alerter
    alerter := alerter.New(cfg, db, filter)
    alerter.Start()
    // Webapp
    go webapp.Start(cfg, db)
    // Detector
    detector := detector.New(cfg, db, filter)
    detector.Out(alerter.In)
    detector.Start()
}

开发者ID:nrzipher,项目名称:banshee,代码行数:52,代码来源:main.go

示例3: main

func main() {
    flag.Usage = func() {
        fmt.Fprintf(os.Stderr, usage)
        fmt.Fprintln(os.Stderr, "Flags:")
        flag.PrintDefaults()
        os.Exit(2)
    }

    flag.Parse()
    if (flag.NFlag() == 0 && flag.NArg() != 2) || (flag.NFlag() == 1 && flag.NArg() > 1) {
        flag.Usage()
    }

    addr := flag.Arg(0)
    if !strings.Contains(addr, ":") {
        addr = ":" + addr
    }

    // Server mode
    if *listen {
        l, err := net.Listen("tcp", addr)
        if err != nil {
            log.Fatal(err)
        }
        defer l.Close()

        log.Fatal(Serve(l))
    }

    // Client mode
    conn, err := Dial(addr)
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()

    buf := []byte(flag.Arg(1))
    if _, err := conn.Write(buf); err != nil {
        log.Fatal(err)
    }

    n, err := conn.Read(buf)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%s\n", buf[:n])
}

开发者ID:billyboar,项目名称:GCSolutions,代码行数:48,代码来源:main.go

示例4: main

func main() {
    defer glog.Flush()

    if flag.NFlag() == 0 {
        flag.PrintDefaults()
        return
    }
    if pv {
        printVersion()
        return
    }

    if len(listenArgs) == 0 {
        glog.Fatalln("no listen addr")
    }

    var wg sync.WaitGroup
    for _, args := range listenArgs {
        wg.Add(1)
        go func(arg Args) {
            defer wg.Done()
            listenAndServe(arg)
        }(args)
    }
    wg.Wait()
}

开发者ID:noscripter,项目名称:gost-1,代码行数:26,代码来源:main.go

示例5: main

func main() {
    flag.Parse()
    isPublic := !*gistPrivateFlag

    // if nothing was given write message
    if (flag.NFlag() == 0) && (len(flag.Args()) == 0) {
        fmt.Println("No arguments or files given!")
        fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
        flag.PrintDefaults()
        os.Exit(2)
    }

    token := Configuration.GetToken()

    if *listGistsFlag != "" {
        username := *listGistsFlag
        url := baseUrl + "users/" + username + "/gists"
        Gist.List(url)
    } else if *deleteGistFlag != "" {
        Gist.Delete(baseUrl, token, *deleteGistFlag)
    } else if *downloadGistFlag != "" {
        Gist.Download(baseUrl, token, *downloadGistFlag)
    } else {
        filesName := flag.Args()
        if len(filesName) == 0 && *updateGistFlag == "" {
            fmt.Println("No files given!")
            os.Exit(2)
        }
        if *updateGistFlag != "" {
            Gist.Update(baseUrl, token, filesName, *updateGistFlag, *gistDescriptionFlag, *openBrowserFlag)
        } else {
            Gist.Post(baseUrl, token, isPublic, filesName, *gistDescriptionFlag, *openBrowserFlag)
        }
    }
}

开发者ID:ramtiga,项目名称:gost,代码行数:35,代码来源:gost.go

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