File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 11package command
22
33import (
4- "errors"
54 "fmt"
65 "os"
76
@@ -19,13 +18,14 @@ func init() {
1918 // RootCmd.PersistentFlags().BoolP("verbose", "V", false, "enable verbose output")
2019
2120 RootCmd .SetFlagErrorFunc (func (cmd * cobra.Command , err error ) error {
22- cmd .Println (err )
23- cmd .Println (cmd .UsageString ())
24- return SilentErr
21+ return FlagError {err }
2522 })
2623}
2724
28- var SilentErr = errors .New ("SilentErr" )
25+ // FlagError is the kind of error raised in flag processing
26+ type FlagError struct {
27+ error
28+ }
2929
3030// RootCmd is the entry point of command-line execution
3131var RootCmd = & cobra.Command {
Original file line number Diff line number Diff line change @@ -3,14 +3,17 @@ package main
33import (
44 "fmt"
55 "os"
6+ "strings"
67
78 "github.com/github/gh-cli/command"
89)
910
1011func main () {
11- if err := command .RootCmd .Execute (); err != nil {
12- if err != command .SilentErr {
13- fmt .Fprintln (os .Stderr , err )
12+ if cmd , err := command .RootCmd .ExecuteC (); err != nil {
13+ fmt .Fprintln (os .Stderr , err )
14+ _ , isFlagError := err .(command.FlagError )
15+ if isFlagError || strings .HasPrefix (err .Error (), "unknown command " ) {
16+ fmt .Fprintln (os .Stderr , cmd .UsageString ())
1417 }
1518 os .Exit (1 )
1619 }
You can’t perform that action at this time.
0 commit comments