From 739037fc37b69f908afe2fbaab2b22ced6fc6fdf Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Thu, 14 May 2020 21:56:36 +0200 Subject: [PATCH] Have the --help/-h flag print usage. pflag will output a "pflag: help requested" message after displaying the usage if we don't explicitly handle the flag. --- cmd/task/task.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/task/task.go b/cmd/task/task.go index c791ff39..f08de1d1 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -49,6 +49,7 @@ func main() { var ( versionFlag bool + helpFlag bool init bool list bool status bool @@ -65,6 +66,7 @@ func main() { ) pflag.BoolVar(&versionFlag, "version", false, "show Task version") + pflag.BoolVarP(&helpFlag, "help", "h", false, "shows Task usage") pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder") pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile") pflag.BoolVar(&status, "status", false, "exits with non-zero exit code if any of the given tasks is not up-to-date") @@ -85,6 +87,11 @@ func main() { return } + if helpFlag { + pflag.Usage() + return + } + if init { wd, err := os.Getwd() if err != nil {