@@ -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
0 commit comments