add flag: -h, --help (#218)

Change-Id: I6d5648b84536c22e518413d0360047431b1acccc
This commit is contained in:
lilihx 2022-07-05 20:06:44 +08:00 committed by GitHub
parent 751e5865da
commit 95009b06b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -22,6 +22,7 @@ func usage(keyMap KeyMap) string {
curl ... | fx
%v
-h, --help print help
-v, --version print version
--print-code print code of the reducer

View File

@ -22,6 +22,7 @@ import (
)
var (
flagHelp bool
flagVersion bool
flagPrintCode bool
)
@ -30,6 +31,8 @@ func main() {
var args []string
for _, arg := range os.Args[1:] {
switch arg {
case "-h", "--help":
flagHelp = true
case "-v", "-V", "--version":
flagVersion = true
case "--print-code":
@ -39,6 +42,10 @@ func main() {
}
}
if flagHelp {
fmt.Println(usage(DefaultKeyMap()))
return
}
if flagVersion {
fmt.Println(version)
return