From e06e6f4076088987a49ad00fcf3ab17ae938ddbc Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 15 May 2022 11:27:48 +0200 Subject: [PATCH] fix cmd behaviour for early exit --- cmd/root.go | 15 +++++++++++++++ cmd/version.go | 2 +- flake.nix | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index b5d472f..5596c18 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,3 +33,18 @@ func Execute() { os.Exit(1) } } + +// help redefines the original help func, essentially adding a way to exit the +// application properly after showing help message +func help(*cobra.Command, []string) { + err := Root.Usage() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + os.Exit(0) +} + +func init() { + Root.SetHelpFunc(help) +} diff --git a/cmd/version.go b/cmd/version.go index 7ca497b..8b52b95 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -8,7 +8,7 @@ import ( ) // version holds app version string -var version = "v0.0.12" +var version = "v0.0.13" // used to determine whether to print short or long version string var shortVersion = false diff --git a/flake.nix b/flake.nix index b8a5e8f..87058b8 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ # Generate a user-friendly version number. # version = builtins.substring 0 8 lastModifiedDate; - version = "v0.0.12"; + version = "v0.0.13"; # System types to support. supportedSystems =