From 95009b06b6487db75b7ccd216e34a6f554d90688 Mon Sep 17 00:00:00 2001 From: lilihx <88191432+Lilihx@users.noreply.github.com> Date: Tue, 5 Jul 2022 20:06:44 +0800 Subject: [PATCH] add flag: -h, --help (#218) Change-Id: I6d5648b84536c22e518413d0360047431b1acccc --- help.go | 1 + main.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/help.go b/help.go index 5658c3c..3550ae9 100644 --- a/help.go +++ b/help.go @@ -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 diff --git a/main.go b/main.go index 2c9b17a..089117e 100644 --- a/main.go +++ b/main.go @@ -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