From 8cec7ec8e1edae2d5a0088c991dec2417f788b9d Mon Sep 17 00:00:00 2001 From: Matthew Huxtable Date: Tue, 23 Apr 2024 11:53:39 +0100 Subject: [PATCH] cmd/gitops-pusher: improve error on invalid subcommand Aid diagnosis of invalid subcommands passed to the gitops-pusher, particularly in the context of CI where the cause of the error is non-obvious; an invalid subcommand previously rendered the following error: terminal command () doesn't define an Exec function Fixes #11842. Signed-off-by: Matthew Huxtable --- cmd/gitops-pusher/gitops-pusher.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/gitops-pusher/gitops-pusher.go b/cmd/gitops-pusher/gitops-pusher.go index 60bee6064..55558a1f8 100644 --- a/cmd/gitops-pusher/gitops-pusher.go +++ b/cmd/gitops-pusher/gitops-pusher.go @@ -11,6 +11,7 @@ import ( "context" "crypto/sha256" "encoding/json" + "errors" "flag" "fmt" "log" @@ -216,6 +217,14 @@ func main() { } if err := root.Parse(os.Args[1:]); err != nil { + if noexec := (ffcli.NoExecError{}); errors.As(err, &noexec) { + if args := noexec.Command.FlagSet.Args(); len(args) > 0 { + log.Fatalf("invalid subcommand %s, see -help for available subcommands", args[0]) + } else { + log.Fatal("missing subcommand, see -help for available subcommands") + } + } + log.Fatal(err) }