Skip to content

Commit efd8894

Browse files
authored
Add flag to print the CLI version (#79)
1 parent 85d00c0 commit efd8894

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Options:
120120
variable.
121121
122122
-url=url GitHub API URL. If unset, use https://api.github.com.
123+
124+
-v/-version Print the version and exit.
123125
```
124126

125127
## Usage: Library

cmd/patch2pr/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"golang.org/x/oauth2"
2222
)
2323

24+
var (
25+
version = "snapshot"
26+
)
27+
2428
func die(code int, err error) {
2529
fmt.Fprintln(os.Stderr, "error:", err)
2630

@@ -80,6 +84,10 @@ func main() {
8084
fs.StringVar(&opts.GitHubToken, "token", "", "token")
8185
fs.Var(URLValue{&opts.GitHubURL}, "url", "url")
8286

87+
var printVersion bool
88+
fs.BoolVar(&printVersion, "v", false, "version")
89+
fs.BoolVar(&printVersion, "version", false, "version")
90+
8391
if err := fs.Parse(os.Args[1:]); err != nil {
8492
if err == flag.ErrHelp {
8593
fmt.Fprintln(os.Stdout, helpText())
@@ -88,6 +96,11 @@ func main() {
8896
die(2, err)
8997
}
9098

99+
if printVersion {
100+
fmt.Fprintln(os.Stdout, version)
101+
os.Exit(0)
102+
}
103+
91104
if opts.Repository == nil {
92105
die(2, errors.New("the -repository flag is required"))
93106
}
@@ -520,6 +533,8 @@ Options:
520533
521534
-url=url GitHub API URL. If unset, use https://api.github.com.
522535
536+
-v/-version Print the version and exit.
537+
523538
`
524539
return strings.TrimSpace(help)
525540
}

0 commit comments

Comments
 (0)