Skip to content

Commit a199de0

Browse files
authored
Merge pull request cli#4577 from cli/no-remote
gh cs cp: report error if no filename is remote
2 parents cd9971b + 7215522 commit a199de0

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

pkg/cmd/codespace/ssh.go

Lines changed: 7 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
)
@@ -193,16 +194,18 @@ users; see https://lwn.net/Articles/835962/ for discussion.
193194

194195
// Copy copies files between the local and remote file systems.
195196
// The mechanics are similar to 'ssh' but using 'scp'.
196-
func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) (err error) {
197+
func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) error {
197198
if len(args) < 2 {
198199
return fmt.Errorf("cp requires source and destination arguments")
199200
}
200201
if opts.recursive {
201202
opts.scpArgs = append(opts.scpArgs, "-r")
202203
}
203204
opts.scpArgs = append(opts.scpArgs, "--")
205+
hasRemote := false
204206
for _, arg := range args {
205207
if rest := strings.TrimPrefix(arg, "remote:"); rest != arg {
208+
hasRemote = true
206209
// scp treats each filename argument as a shell expression,
207210
// subjecting it to expansion of environment variables, braces,
208211
// tilde, backticks, globs and so on. Because these present a
@@ -225,6 +228,9 @@ func (a *App) Copy(ctx context.Context, args []string, opts cpOptions) (err erro
225228
}
226229
opts.scpArgs = append(opts.scpArgs, arg)
227230
}
231+
if !hasRemote {
232+
return &cmdutil.FlagError{Err: fmt.Errorf("at least one argument must have a 'remote:' prefix")}
233+
}
228234
return a.SSH(ctx, nil, opts.sshOptions)
229235
}
230236

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)