Skip to content

Commit f4491c7

Browse files
committed
Add FlagErrorf; encapsulate FlagError.error
1 parent a199de0 commit f4491c7

File tree

48 files changed

+103
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+103
-114
lines changed

cmd/gh/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ check your internet connection or https://githubstatus.com
4949
{
5050
name: "Cobra flag error",
5151
args: args{
52-
err: &cmdutil.FlagError{Err: errors.New("unknown flag --foo")},
52+
err: cmdutil.FlagErrorf("unknown flag --foo"),
5353
cmd: cmd,
5454
debug: false,
5555
},

pkg/cmd/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
173173

174174
if c.Flags().Changed("hostname") {
175175
if err := ghinstance.HostnameValidator(opts.Hostname); err != nil {
176-
return &cmdutil.FlagError{Err: fmt.Errorf("error parsing `--hostname`: %w", err)}
176+
return cmdutil.FlagErrorf("error parsing `--hostname`: %w", err)
177177
}
178178
}
179179

180180
if opts.Paginate && !strings.EqualFold(opts.RequestMethod, "GET") && opts.RequestPath != "graphql" {
181-
return &cmdutil.FlagError{Err: errors.New("the `--paginate` option is not supported for non-GET requests")}
181+
return cmdutil.FlagErrorf("the `--paginate` option is not supported for non-GET requests")
182182
}
183183

184184
if err := cmdutil.MutuallyExclusive(

pkg/cmd/auth/login/login.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
6969
`),
7070
RunE: func(cmd *cobra.Command, args []string) error {
7171
if !opts.IO.CanPrompt() && !(tokenStdin || opts.Web) {
72-
return &cmdutil.FlagError{Err: errors.New("--web or --with-token required when not running interactively")}
72+
return cmdutil.FlagErrorf("--web or --with-token required when not running interactively")
7373
}
7474

7575
if tokenStdin && opts.Web {
76-
return &cmdutil.FlagError{Err: errors.New("specify only one of --web or --with-token")}
76+
return cmdutil.FlagErrorf("specify only one of --web or --with-token")
7777
}
7878

7979
if tokenStdin {
@@ -91,7 +91,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
9191

9292
if cmd.Flags().Changed("hostname") {
9393
if err := ghinstance.HostnameValidator(opts.Hostname); err != nil {
94-
return &cmdutil.FlagError{Err: fmt.Errorf("error parsing --hostname: %w", err)}
94+
return cmdutil.FlagErrorf("error parsing --hostname: %w", err)
9595
}
9696
}
9797

pkg/cmd/auth/logout/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Co
4848
`),
4949
RunE: func(cmd *cobra.Command, args []string) error {
5050
if opts.Hostname == "" && !opts.IO.CanPrompt() {
51-
return &cmdutil.FlagError{Err: errors.New("--hostname required when not running interactively")}
51+
return cmdutil.FlagErrorf("--hostname required when not running interactively")
5252
}
5353

5454
if runF != nil {

pkg/cmd/auth/refresh/refresh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.
6262
opts.Interactive = opts.IO.CanPrompt()
6363

6464
if !opts.Interactive && opts.Hostname == "" {
65-
return &cmdutil.FlagError{Err: errors.New("--hostname required when not running interactively")}
65+
return cmdutil.FlagErrorf("--hostname required when not running interactively")
6666
}
6767

6868
opts.MainExecutable = f.Executable()

pkg/cmd/codespace/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func newListCmd(app *App) *cobra.Command {
2020
Args: noArgsConstraint,
2121
RunE: func(cmd *cobra.Command, args []string) error {
2222
if limit < 1 {
23-
return &cmdutil.FlagError{Err: fmt.Errorf("invalid limit: %v", limit)}
23+
return cmdutil.FlagErrorf("invalid limit: %v", limit)
2424
}
2525

2626
return app.List(cmd.Context(), asJSON, limit)

pkg/cmd/codespace/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) error {
229229
opts.scpArgs = append(opts.scpArgs, arg)
230230
}
231231
if !hasRemote {
232-
return &cmdutil.FlagError{Err: fmt.Errorf("at least one argument must have a 'remote:' prefix")}
232+
return cmdutil.FlagErrorf("at least one argument must have a 'remote:' prefix")
233233
}
234234
return a.SSH(ctx, nil, opts.sshOptions)
235235
}

pkg/cmd/completion/completion.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package completion
22

33
import (
4-
"errors"
54
"fmt"
65

76
"github.com/MakeNowJust/heredoc"
@@ -68,7 +67,7 @@ func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command {
6867
RunE: func(cmd *cobra.Command, args []string) error {
6968
if shellType == "" {
7069
if io.IsStdoutTTY() {
71-
return &cmdutil.FlagError{Err: errors.New("error: the value for `--shell` is required")}
70+
return cmdutil.FlagErrorf("error: the value for `--shell` is required")
7271
}
7372
shellType = "bash"
7473
}

pkg/cmd/extension/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
117117
Short: "Upgrade installed extensions",
118118
Args: func(cmd *cobra.Command, args []string) error {
119119
if len(args) == 0 && !flagAll {
120-
return &cmdutil.FlagError{Err: errors.New("must specify an extension to upgrade")}
120+
return cmdutil.FlagErrorf("must specify an extension to upgrade")
121121
}
122122
if len(args) > 0 && flagAll {
123-
return &cmdutil.FlagError{Err: errors.New("cannot use `--all` with extension name")}
123+
return cmdutil.FlagErrorf("cannot use `--all` with extension name")
124124
}
125125
if len(args) > 1 {
126-
return &cmdutil.FlagError{Err: errors.New("too many arguments")}
126+
return cmdutil.FlagErrorf("too many arguments")
127127
}
128128
return nil
129129
},

pkg/cmd/gist/clone/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Comm
6161
if err == pflag.ErrHelp {
6262
return err
6363
}
64-
return &cmdutil.FlagError{Err: fmt.Errorf("%w\nSeparate git clone flags with '--'.", err)}
64+
return cmdutil.FlagErrorf("%w\nSeparate git clone flags with '--'.", err)
6565
})
6666

6767
return cmd

0 commit comments

Comments
 (0)