Merge branch 'master' into version-flag

This commit is contained in:
Mislav Marohnić 2019-10-31 23:13:07 +01:00 committed by GitHub
commit 2939924124
2 changed files with 19 additions and 2 deletions

View file

@ -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

View file

@ -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)
}
}