use FlagError
This commit is contained in:
parent
8fb5e5e1d5
commit
7215522123
4 changed files with 9 additions and 7 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/cli/cli/v2/pkg/liveshare"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -228,7 +229,7 @@ func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) error {
|
|||
opts.scpArgs = append(opts.scpArgs, arg)
|
||||
}
|
||||
if !hasRemote {
|
||||
return fmt.Errorf("cp: no argument is a 'remote:' filename")
|
||||
return &cmdutil.FlagError{Err: fmt.Errorf("at least one argument must have a 'remote:' prefix")}
|
||||
}
|
||||
return a.SSH(ctx, nil, opts.sshOptions)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
|
|||
Use: "fork [<repository>] [-- <gitflags>...]",
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if cmd.ArgsLenAtDash() == 0 && len(args[1:]) > 0 {
|
||||
return cmdutil.FlagError{Err: fmt.Errorf("repository argument required when passing 'git clone' flags")}
|
||||
return &cmdutil.FlagError{Err: fmt.Errorf("repository argument required when passing 'git clone' flags")}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func NewCmdRun(f *cmdutil.Factory, runF func(*RunOptions) error) *cobra.Command
|
|||
`),
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if len(opts.MagicFields)+len(opts.RawFields) > 0 && len(args) == 0 {
|
||||
return cmdutil.FlagError{Err: fmt.Errorf("workflow argument required when passing -f or -F")}
|
||||
return &cmdutil.FlagError{Err: fmt.Errorf("workflow argument required when passing -f or -F")}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
@ -103,7 +103,7 @@ func NewCmdRun(f *cmdutil.Factory, runF func(*RunOptions) error) *cobra.Command
|
|||
}
|
||||
opts.JSONInput = string(jsonIn)
|
||||
} else if opts.JSON {
|
||||
return cmdutil.FlagError{Err: errors.New("--json specified but nothing on STDIN")}
|
||||
return &cmdutil.FlagError{Err: errors.New("--json specified but nothing on STDIN")}
|
||||
}
|
||||
|
||||
if opts.Selector == "" {
|
||||
|
|
|
|||
|
|
@ -6,16 +6,17 @@ import (
|
|||
"github.com/AlecAivazis/survey/v2/terminal"
|
||||
)
|
||||
|
||||
// FlagError is the kind of error raised in flag processing
|
||||
// A *FlagError indicates an error processing command-line flags or other arguments.
|
||||
// Such errors cause the application to display the usage message.
|
||||
type FlagError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (fe FlagError) Error() string {
|
||||
func (fe *FlagError) Error() string {
|
||||
return fe.Err.Error()
|
||||
}
|
||||
|
||||
func (fe FlagError) Unwrap() error {
|
||||
func (fe *FlagError) Unwrap() error {
|
||||
return fe.Err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue