Skip to content

Commit

Permalink
Add -version flag to show version and exit with zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeken committed Sep 8, 2020
1 parent 452a277 commit 780c817
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
appID := flag.Int64("app-id", 0, "App ID")
instID := flag.Int64("inst-id", 0, "Installation ID")
export := flag.Bool("export", false, "show token as 'export GITHUB_TOKEN=...'")
showVersion := flag.Bool("version", false, "show version info")

origUsage := flag.Usage
flag.Usage = func() {
Expand All @@ -37,6 +38,13 @@ func main() {

flag.Parse()

// See https://github.com/golang/go/issues/37533
// I decided to implement -version flag to return 0
if *showVersion {
flag.Usage()
os.Exit(0)
}

if *appID == 0 || *instID == 0 {
fmt.Fprintf(os.Stderr, "App ID and Installation ID are required.\n\n")
flag.Usage()
Expand Down

0 comments on commit 780c817

Please sign in to comment.