Merge branch 'master' into version-flag
This commit is contained in:
commit
2939924124
2 changed files with 19 additions and 2 deletions
|
|
@ -22,6 +22,15 @@ func init() {
|
|||
RootCmd.PersistentFlags().StringP("current-branch", "B", "", "current git branch")
|
||||
// TODO:
|
||||
// RootCmd.PersistentFlags().BoolP("verbose", "V", false, "enable verbose output")
|
||||
|
||||
RootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||
return FlagError{err}
|
||||
})
|
||||
}
|
||||
|
||||
// FlagError is the kind of error raised in flag processing
|
||||
type FlagError struct {
|
||||
error
|
||||
}
|
||||
|
||||
// RootCmd is the entry point of command-line execution
|
||||
|
|
@ -29,6 +38,9 @@ var RootCmd = &cobra.Command{
|
|||
Use: "gh",
|
||||
Short: "GitHub CLI",
|
||||
Long: `Do things with GitHub from your terminal`,
|
||||
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
// overriden in tests
|
||||
|
|
|
|||
9
main.go
9
main.go
|
|
@ -3,13 +3,18 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/github/gh-cli/command"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := command.RootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
if cmd, err := command.RootCmd.ExecuteC(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
_, isFlagError := err.(command.FlagError)
|
||||
if isFlagError || strings.HasPrefix(err.Error(), "unknown command ") {
|
||||
fmt.Fprintln(os.Stderr, cmd.UsageString())
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue