From 9e8e65ccf0084ac44422a6b1e8a00aa501a86037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Wed, 25 Jul 2018 18:03:38 +0200 Subject: Parse command-line arguments --- aports-ghpr.go | 30 ++++++++++++++++++++++++------ 1 file 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) } -- cgit v1.2.3