From 4a114911d1d0f8982c727a3b9f4e1fbac6698a4b Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Thu, 22 Apr 2021 22:21:59 -0700 Subject: [PATCH] Don't display usage info when a command returns with an error Just display the error and exit the program. Signed-off-by: Jan Dubois --- cmd/root.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index d8f15da..ba00bed 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,6 +20,11 @@ var ( as well as a lightweight control program to create/access/delete virtual machines running via hyperkit.`, Version: hyperkit.GetVersion(), + PersistentPreRun: func(cmd *cobra.Command, args []string) { + // Don't display usage information when a RunE command returns an error. + // Just print the error and exit. + cmd.SilenceUsage = true + }, } )