Skip to content

Commit

Permalink
gitops-pusher: friendlier error on invalid subcommand
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mhuxtable committed Apr 23, 2024
1 parent 9779eb6 commit 6f209ed
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/gitops-pusher/gitops-pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 6f209ed

Please sign in to comment.