()
| 59 | } |
| 60 | |
| 61 | func main() { |
| 62 | var opts Options |
| 63 | |
| 64 | fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) |
| 65 | fs.SetOutput(io.Discard) |
| 66 | fs.Usage = func() {} |
| 67 | |
| 68 | fs.StringVar(&opts.BaseBranch, "base-branch", "", "base-branch") |
| 69 | fs.BoolVar(&opts.Draft, "draft", false, "draft") |
| 70 | fs.BoolVar(&opts.Force, "force", false, "force") |
| 71 | fs.BoolVar(&opts.Fork, "fork", false, "fork") |
| 72 | fs.Var(ForkValue{RepositoryValue{&opts.ForkRepository}, &opts.Fork}, "fork-repository", "fork-repository") |
| 73 | fs.StringVar(&opts.HeadBranch, "head-branch", "patch2pr", "head-branch") |
| 74 | fs.BoolVar(&opts.OutputJSON, "json", false, "json") |
| 75 | fs.StringVar(&opts.Message, "message", "", "message") |
| 76 | fs.BoolVar(&opts.NoPullRequest, "no-pull-request", false, "no-pull-request") |
| 77 | fs.StringVar(&opts.PatchBase, "patch-base", "", "patch-base") |
| 78 | fs.StringVar(&opts.PullBody, "pull-body", "", "pull-body") |
| 79 | fs.StringVar(&opts.PullTitle, "pull-title", "", "pull-title") |
| 80 | fs.Var(RepositoryValue{&opts.Repository}, "repository", "repository") |
| 81 | fs.StringVar(&opts.GitHubToken, "token", "", "token") |
| 82 | fs.StringVar(&opts.GitHubURL, "url", "https://api.github.com/", "url") |
| 83 | |
| 84 | var printVersion bool |
| 85 | fs.BoolVar(&printVersion, "v", false, "version") |
| 86 | fs.BoolVar(&printVersion, "version", false, "version") |
| 87 | |
| 88 | if err := fs.Parse(os.Args[1:]); err != nil { |
| 89 | if err == flag.ErrHelp { |
| 90 | fmt.Fprintln(os.Stdout, helpText()) |
| 91 | os.Exit(0) |
| 92 | } |
| 93 | die(2, err) |
| 94 | } |
| 95 | |
| 96 | if printVersion { |
| 97 | fmt.Fprintln(os.Stdout, version) |
| 98 | os.Exit(0) |
| 99 | } |
| 100 | |
| 101 | if opts.Repository == nil { |
| 102 | die(2, errors.New("the -repository flag is required")) |
| 103 | } |
| 104 | if opts.GitHubToken == "" { |
| 105 | if t, ok := os.LookupEnv("GITHUB_TOKEN"); ok { |
| 106 | opts.GitHubToken = t |
| 107 | } else { |
| 108 | die(2, errors.New("a github token is required; use -token or set GITHUB_TOKEN")) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | ctx := context.Background() |
| 113 | tc := internal.NewTokenClient(opts.GitHubToken) |
| 114 | |
| 115 | client, err := github.NewClient( |
| 116 | github.WithHTTPClient(tc), |
| 117 | github.WithURLs(&opts.GitHubURL, nil), |
| 118 | ) |
nothing calls this directly
no test coverage detected