X Tutup
Skip to content

Commit 7215522

Browse files
committed
use FlagError
1 parent 8fb5e5e commit 7215522

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

pkg/cmd/codespace/ssh.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414

1515
"github.com/cli/cli/v2/internal/codespaces"
16+
"github.com/cli/cli/v2/pkg/cmdutil"
1617
"github.com/cli/cli/v2/pkg/liveshare"
1718
"github.com/spf13/cobra"
1819
)
@@ -228,7 +229,7 @@ func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) error {
228229
opts.scpArgs = append(opts.scpArgs, arg)
229230
}
230231
if !hasRemote {
231-
return fmt.Errorf("cp: no argument is a 'remote:' filename")
232+
return &cmdutil.FlagError{Err: fmt.Errorf("at least one argument must have a 'remote:' prefix")}
232233
}
233234
return a.SSH(ctx, nil, opts.sshOptions)
234235
}

pkg/cmd/repo/fork/fork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
6161
Use: "fork [<repository>] [-- <gitflags>...]",
6262
Args: func(cmd *cobra.Command, args []string) error {
6363
if cmd.ArgsLenAtDash() == 0 && len(args[1:]) > 0 {
64-
return cmdutil.FlagError{Err: fmt.Errorf("repository argument required when passing 'git clone' flags")}
64+
return &cmdutil.FlagError{Err: fmt.Errorf("repository argument required when passing 'git clone' flags")}
6565
}
6666
return nil
6767
},

pkg/cmd/workflow/run/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewCmdRun(f *cmdutil.Factory, runF func(*RunOptions) error) *cobra.Command
7878
`),
7979
Args: func(cmd *cobra.Command, args []string) error {
8080
if len(opts.MagicFields)+len(opts.RawFields) > 0 && len(args) == 0 {
81-
return cmdutil.FlagError{Err: fmt.Errorf("workflow argument required when passing -f or -F")}
81+
return &cmdutil.FlagError{Err: fmt.Errorf("workflow argument required when passing -f or -F")}
8282
}
8383
return nil
8484
},
@@ -103,7 +103,7 @@ func NewCmdRun(f *cmdutil.Factory, runF func(*RunOptions) error) *cobra.Command
103103
}
104104
opts.JSONInput = string(jsonIn)
105105
} else if opts.JSON {
106-
return cmdutil.FlagError{Err: errors.New("--json specified but nothing on STDIN")}
106+
return &cmdutil.FlagError{Err: errors.New("--json specified but nothing on STDIN")}
107107
}
108108

109109
if opts.Selector == "" {

pkg/cmdutil/errors.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import (
66
"github.com/AlecAivazis/survey/v2/terminal"
77
)
88

9-
// FlagError is the kind of error raised in flag processing
9+
// A *FlagError indicates an error processing command-line flags or other arguments.
10+
// Such errors cause the application to display the usage message.
1011
type FlagError struct {
1112
Err error
1213
}
1314

14-
func (fe FlagError) Error() string {
15+
func (fe *FlagError) Error() string {
1516
return fe.Err.Error()
1617
}
1718

18-
func (fe FlagError) Unwrap() error {
19+
func (fe *FlagError) Unwrap() error {
1920
return fe.Err
2021
}
2122

0 commit comments

Comments
 (0)
X Tutup