diff options
author | Sören Tempel <soeren+git@soeren-tempel.net> | 2018-07-25 18:03:38 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2018-07-26 12:22:21 +0200 |
commit | 9e8e65ccf0084ac44422a6b1e8a00aa501a86037 (patch) | |
tree | 89fab488ef82d8aabafbaf33aa971f57c9a7bb6f | |
parent | 0cef36e0723547a1e6e960791fdfa4ba2e768a2c (diff) | |
download | aports-ghpr-9e8e65ccf0084ac44422a6b1e8a00aa501a86037.tar.bz2 aports-ghpr-9e8e65ccf0084ac44422a6b1e8a00aa501a86037.tar.xz |
Parse command-line arguments
-rw-r--r-- | aports-ghpr.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/aports-ghpr.go b/aports-ghpr.go index 72bcd87..1d5eaf0 100644 --- a/aports-ghpr.go +++ b/aports-ghpr.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "fmt" "github.com/google/go-github/github" "log" @@ -10,10 +11,26 @@ import ( "strings" ) +var ( + owner = flag.String("o", "alpinelinux", "GitHub username of the repository owner") + repo = flag.String("r", "aports", "Name of the GitHub repository") +) + +func usage() { + fmt.Fprintf(flag.CommandLine.Output(), "USAGE: %s [FLAGS] [APORT]\n\n"+ + "The following flags are supported:\n\n", os.Args[0]) + flag.PrintDefaults() +} + func main() { - // TODO: parse options from command line + flag.Usage = usage + flag.Parse() + + var aport string + if flag.NArg() >= 1 { + aport = flag.Arg(0) + } - var aport string = "" // if APKBUILD exists in current directory, then we limit the search if _, err := os.Stat("APKBUILD"); err == nil { @@ -25,9 +42,10 @@ func main() { fmt.Println("searching for: ", aport) } - // TODO: allow set this in some config file - owner := "alpinelinux" - repo := "aports" + if aport == "" { + usage() + os.Exit(1) + } // TODO: allow set authentication client := github.NewClient(nil) @@ -38,7 +56,7 @@ func main() { ListOptions: github.ListOptions{PerPage: 200}, } for { - prs, resp, err := client.PullRequests.List(ctx, owner, repo, opt) + prs, resp, err := client.PullRequests.List(ctx, *owner, *repo, opt) if err != nil { log.Fatal(err) } |