File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,25 @@ func init() {
2222 RootCmd .PersistentFlags ().StringP ("current-branch" , "B" , "" , "current git branch" )
2323 // TODO:
2424 // RootCmd.PersistentFlags().BoolP("verbose", "V", false, "enable verbose output")
25+
26+ RootCmd .SetFlagErrorFunc (func (cmd * cobra.Command , err error ) error {
27+ return FlagError {err }
28+ })
29+ }
30+
31+ // FlagError is the kind of error raised in flag processing
32+ type FlagError struct {
33+ error
2534}
2635
2736// RootCmd is the entry point of command-line execution
2837var RootCmd = & cobra.Command {
2938 Use : "gh" ,
3039 Short : "GitHub CLI" ,
3140 Long : `Do things with GitHub from your terminal` ,
41+
42+ SilenceErrors : true ,
43+ SilenceUsage : true ,
3244}
3345
3446// overriden in tests
Original file line number Diff line number Diff line change @@ -3,13 +3,18 @@ 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- fmt .Println (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 ())
17+ }
1318 os .Exit (1 )
1419 }
1520}
You can’t perform that action at this time.
0 commit comments