| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package main
- import (
- "fmt"
- "os"
- "strconv"
- )
- // TODO regex on type.. user/organization can be treated as the same:
- // hittps://github.com/<user or org>
- // hittps://github.com/<user or org>/repo
- const usage = `usage: gitleaks [git link] [options]
- Options:
- -c Concurrency factor (potential number of git files open)
- -h --help Display this message
- `
- type Options struct {
- Concurrency int
- }
- func help() {
- os.Stderr.WriteString(usage)
- os.Exit(1)
- }
- func optionsNextInt(args []string, i *int) int {
- if len(args) > *i+1 {
- *i++
- } else {
- help()
- }
- argInt, err := strconv.Atoi(args[*i])
- if err != nil {
- fmt.Printf("Invalid %s option: %s\n", args[*i-1], args[*i])
- help()
- }
- return argInt
- }
- func parseOptions(args []string) *Options {
- opts := &Options{}
- for i := 0; i < len(args); i++ {
- arg := args[i]
- switch arg {
- case "-c":
- opts.Concurrency = optionsNextInt(args, &i)
- case "-h", "--help":
- help()
- return nil
- default:
- fmt.Printf("Uknown option %s\n\n", arg)
- help()
- return nil
- }
- }
- return opts
- }
|