-
Notifications
You must be signed in to change notification settings - Fork 239
/
op.go
198 lines (179 loc) · 5.08 KB
/
op.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Package op defines types of operations and their accepted options.
package op
import (
"fmt"
"github.com/peak/s5cmd/opt"
)
// Operation is a type of our operations.
type Operation int
// List of Operations
const (
Abort Operation = iota // Abort program
Download // Download from S3 to local
BatchDownload // Batch download from S3 to local
Upload // Upload from local to S3
BatchUpload // Batch upload from local to S3
Copy // Copy from S3 to S3
BatchCopy // Batch copy from S3 to S3
Delete // Delete from S3
Size // List S3 and get object sizes
BatchDelete // "ls" and submit batched multi-delete operations
BatchDeleteActual // AWS deleteObjects call
List // List S3 objects
ListBuckets // List S3 buckets
LocalCopy // Copy from local to local
BatchLocalCopy // Batch copy from local to local
LocalDelete // Delete local file
ShellExec // Execute shell command
AliasGet // Alias for Download
AliasBatchGet // Alias for BatchDownload
ShowHelp // Show help for command
)
// IsBatch returns true if this operation creates sub-jobs
func (o Operation) IsBatch() bool {
return o == BatchDownload || o == BatchUpload || o == BatchDelete || o == BatchLocalCopy || o == BatchCopy || o == AliasBatchGet
}
// IsInternal returns true if this operation is considered internal. Internal operations are not shown in +OK messages
func (o Operation) IsInternal() bool {
return o == BatchDeleteActual
}
func (o Operation) String() string {
switch o {
case Abort:
return "abort"
case Download:
return "download"
case BatchDownload:
return "batch-download"
case Upload:
return "upload"
case BatchUpload:
return "batch-upload"
case Copy:
return "copy"
case BatchCopy:
return "batch-copy"
case Delete:
return "delete"
case BatchDelete:
return "batch-delete"
case BatchDeleteActual:
return "batch-delete-actual"
case ListBuckets:
return "ls-buckets"
case List:
return "ls"
case Size:
return "du"
case LocalCopy:
return "local-copy"
case BatchLocalCopy:
return "batch-local-copy"
case LocalDelete:
return "local-delete"
case ShellExec:
return "shell-exec"
case AliasGet:
return "get"
case AliasBatchGet:
return "batch-get"
case ShowHelp:
return "show-help"
}
return fmt.Sprintf("Unknown:%d", o)
}
// Describe returns string description of the Operation given a specific OptionList
func (o Operation) Describe(l opt.OptionList) string {
switch o {
case Abort:
return "Exit program"
case Download, AliasGet:
if l.Has(opt.DeleteSource) {
return "Download from S3 and delete source objects"
}
return "Download from S3"
case BatchDownload, AliasBatchGet:
if l.Has(opt.DeleteSource) {
return "Batch download from S3 and delete source objects"
}
return "Batch download from S3"
case Upload:
if l.Has(opt.DeleteSource) {
return "Upload to S3 and delete source files"
}
return "Upload to S3"
case BatchUpload:
if l.Has(opt.DeleteSource) {
return "Batch upload to S3 and delete source files"
}
return "Batch upload to S3"
case Copy:
if l.Has(opt.DeleteSource) {
return "Move S3 object"
}
return "Copy S3 object"
case BatchCopy:
if l.Has(opt.DeleteSource) {
return "Batch move S3 objects"
}
return "Batch copy S3 objects"
case Delete:
return "Delete from S3"
case BatchDelete:
return "Batch delete from S3"
case ListBuckets:
return "List buckets"
case List:
return "List objects"
case Size:
return "Count objects and size"
case LocalCopy:
if l.Has(opt.DeleteSource) {
return "Move local files"
}
return "Copy local files"
case BatchLocalCopy:
if l.Has(opt.DeleteSource) {
return "Batch move local files"
}
return "Batch copy local files"
case LocalDelete:
return "Delete local files"
case ShellExec:
return "Arbitrary shell-execute"
}
return fmt.Sprintf("Unknown:%d", o)
}
// GetAcceptedOpts returns an opt.OptionList of optional parameters for a specific Operation
func (o Operation) GetAcceptedOpts() *opt.OptionList {
l := opt.OptionList{opt.Help}
switch o {
case Download, Upload, Copy, LocalCopy, BatchDownload, BatchUpload, BatchLocalCopy, BatchCopy, AliasGet, AliasBatchGet:
l = append(l, opt.IfNotExists, opt.IfSizeDiffers, opt.IfSourceNewer)
}
switch o {
case BatchDownload, BatchUpload, BatchLocalCopy, BatchCopy, AliasBatchGet:
l = append(l, opt.Parents)
}
switch o {
case Upload, BatchUpload, Copy, BatchCopy:
l = append(l, opt.RR, opt.IA)
}
switch o {
case BatchLocalCopy:
l = append(l, opt.Recursive)
}
switch o {
case List:
l = append(l, opt.ListETags)
}
switch o {
case List, Size:
l = append(l, opt.HumanReadable)
}
switch o {
case Size:
l = append(l, opt.GroupByClass)
}
return &l
}