Print friendly error when "gh repo clone" is missing required argument

This commit is contained in:
Eric Hagman 2020-10-21 23:15:58 -04:00
parent 2afc462cd0
commit af1d8a60e0
2 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package clone
import (
"errors"
"fmt"
"net/http"
"strings"
@ -37,8 +38,13 @@ func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Comm
cmd := &cobra.Command{
DisableFlagsInUseLine: true,
Use: "clone <repository> [<directory>] [-- <gitflags>...]",
Args: cobra.MinimumNArgs(1),
Use: "clone <repository> [<directory>] [-- <gitflags>...]",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return &cmdutil.FlagError{Err: errors.New("cannot clone: no repository name given")}
}
return nil
},
Short: "Clone a repository locally",
Long: heredoc.Doc(`
Clone a GitHub repository locally.

View file

@ -210,3 +210,10 @@ func Test_RepoClone_flagError(t *testing.T) {
t.Errorf("unexpected error %v", err)
}
}
func Test_RepoClone_noArgError(t *testing.T) {
_, err := runCloneCommand(nil, "")
if err == nil || err.Error() != "cannot clone: no repository name given" {
t.Errorf("unexpected error %v", err)
}
}