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 <git@tigermatt.uk>
This commit is contained in:
parent
9779eb6dba
commit
8cec7ec8e1
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue