Skip to content

Commit

Permalink
use FlagError
Browse files Browse the repository at this point in the history
  • Loading branch information
adonovan committed Oct 21, 2021
1 parent 8fb5e5e commit 7215522
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/cmd/codespace/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/repo/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/workflow/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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 == "" {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmdutil/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7215522

Please sign in to comment.