forked from peak/s5cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmv.go
65 lines (51 loc) · 1.69 KB
/
mv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package command
import (
"github.com/peak/s5cmd/v2/log/stat"
"github.com/urfave/cli/v2"
)
var moveHelpTemplate = `Name:
{{.HelpName}} - {{.Usage}}
Usage:
{{.HelpName}} [options] source destination
Options:
{{range .VisibleFlags}}{{.}}
{{end}}
Examples:
1. Move an S3 object to working directory
> s5cmd {{.HelpName}} s3://bucket/prefix/object.gz .
2. Move an S3 object and rename
> s5cmd {{.HelpName}} s3://bucket/prefix/object.gz myobject.gz
3. Move all S3 objects to a directory
> s5cmd {{.HelpName}} "s3://bucket/*" target-directory/
4. Move a file to S3 bucket
> s5cmd {{.HelpName}} myfile.gz s3://bucket/
5. Move a directory to S3 bucket recursively
> s5cmd {{.HelpName}} dir/ s3://bucket/
6. Move all files to S3 bucket but exclude the ones with txt and gz extension
> s5cmd {{.HelpName}} --exclude "*.txt" --exclude "*.gz" dir/ s3://bucket
7. Move all files from S3 bucket to another S3 bucket but exclude the ones starts with log
> s5cmd {{.HelpName}} --exclude "log*" "s3://bucket/*" s3://destbucket
`
func NewMoveCommand() *cli.Command {
cmd := &cli.Command{
Name: "mv",
HelpName: "mv",
Usage: "move/rename objects",
Flags: NewCopyCommandFlags(), // move and copy commands share the same flags
CustomHelpTemplate: moveHelpTemplate,
Before: func(c *cli.Context) error {
return NewCopyCommand().Before(c)
},
Action: func(c *cli.Context) (err error) {
defer stat.Collect(c.Command.FullName(), &err)()
// delete source
copy, err := NewCopy(c, true)
if err != nil {
return err
}
return copy.Run(c.Context)
},
}
cmd.BashComplete = getBashCompleteFn(cmd, false, false)
return cmd
}