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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//! Clap CLI definitions for sulfite.
use clap::{Parser, Subcommand};
use sulfite::{
DEFAULT_MULTIPART_CHUNK_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_RETRIABLE_CLIENT_STATUS_CODES_STR,
};
/// S3 operations: list, single-object ops, or batch from CSV.
#[derive(Parser)]
#[command(name = "sulfite")]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
/// The AWS region (or the region of the custom endpoint).
#[arg(short, long, global = true)]
pub region: Option<String>,
/// The S3 endpoint URL (e.g. for MinIO or a custom endpoint).
#[arg(short, long, global = true)]
pub endpoint_url: Option<String>,
/// Maximum number of retries per request.
#[arg(long, global = true, default_value = "3")]
pub max_retries: usize,
/// HTTP status codes to treat as retriable client errors (comma-separated).
#[arg(long, global = true, value_delimiter(','), value_parser = clap::value_parser!(u16), num_args(1..), default_value = DEFAULT_RETRIABLE_CLIENT_STATUS_CODES_STR)]
pub retriable_client_status_codes: Vec<u16>,
/// Read timeout in seconds for the HTTP client.
#[arg(long, global = true, default_value_t = DEFAULT_READ_TIMEOUT)]
pub read_timeout: u64,
/// Part size in bytes for multipart upload/download (default: 20 MiB).
#[arg(long, global = true, default_value_t = DEFAULT_MULTIPART_CHUNK_SIZE)]
pub multipart_chunk_size: u64,
/// Number of parallel workers for multipart upload/download.
#[arg(long, global = true, default_value_t = 10)]
pub multipart_workers: usize,
}
#[derive(Subcommand)]
pub enum Command {
/// List objects in a bucket (optional prefix/suffix) and write keys to CSV.
List(ListArgs),
/// Get metadata (HEAD) for one object.
Head(HeadArgs),
/// Download one object (single request).
Download(DownloadArgs),
/// Download one object (multipart transfer).
DownloadMultipart(DownloadMultipartArgs),
/// Upload one object (single request).
Upload(UploadArgs),
/// Upload one object (multipart transfer).
UploadMultipart(UploadMultipartArgs),
/// Delete one object.
Delete(DeleteArgs),
/// Copy one object from source to destination.
Copy(CopyArgs),
/// Restore one object from archival storage (e.g. Glacier).
Restore(RestoreArgs),
/// Run one operation per key from a CSV file (batch).
Csv(CsvArgs),
}
#[derive(Parser, Clone)]
pub struct ListArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The prefix to list under.
#[arg(short, long)]
pub prefix: String,
/// Only list keys that end with this suffix.
#[arg(short, long, default_value = "")]
pub suffix: String,
/// The delimiter for common-prefix grouping (e.g. '/').
#[arg(short, long, default_value = "/")]
pub delimiter: String,
/// Maximum number of object keys and common prefixes to show in the console preview. Does not limit CSV output or listing.
#[arg(short = 'm', long, default_value = "10")]
pub display_max_entries: usize,
/// The path to write the key list as CSV (omit to print to stdout).
#[arg(short, long)]
pub output_path: Option<String>,
/// Keep the prefix in the output keys (by default the prefix is stripped).
#[arg(long, default_value = "false")]
pub keep_prefix: bool,
/// Strip the suffix from the output keys (by default the suffix is kept).
#[arg(long, default_value = "false")]
pub remove_suffix: bool,
}
#[derive(Parser, Clone)]
pub struct HeadArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
}
#[derive(Parser, Clone)]
pub struct DownloadArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
/// The local path to write to (defaults to current directory with filename from key).
#[arg(short, long)]
pub local_path: Option<String>,
/// The start offset in bytes for a range download (optional).
#[arg(long)]
pub start_offset: Option<usize>,
/// The end offset in bytes for a range download (optional).
#[arg(long)]
pub end_offset: Option<usize>,
}
#[derive(Parser, Clone)]
pub struct DownloadMultipartArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
/// The local path to write to (defaults to current directory with filename from key).
#[arg(short, long)]
pub local_path: Option<String>,
/// The number of parallel workers for part downloads.
#[arg(short, long, default_value = "250")]
pub n_workers: usize,
}
#[derive(Parser, Clone)]
pub struct UploadArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
/// The local file path to upload.
#[arg(short, long)]
pub local_path: String,
/// The storage class (e.g. STANDARD, GLACIER).
#[arg(long)]
pub storage_class: Option<String>,
}
#[derive(Parser, Clone)]
pub struct UploadMultipartArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
/// The local file path to upload.
#[arg(short, long)]
pub local_path: String,
/// The storage class (e.g. STANDARD, GLACIER).
#[arg(long)]
pub storage_class: Option<String>,
/// The number of parallel workers for part uploads.
#[arg(short, long, default_value = "250")]
pub n_workers: usize,
}
#[derive(Parser, Clone)]
pub struct DeleteArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
}
#[derive(Parser, Clone)]
pub struct CopyArgs {
/// The source bucket name.
#[arg(long)]
pub src_bucket: String,
/// The source object key.
#[arg(long)]
pub src_key: String,
/// The destination bucket name.
#[arg(long)]
pub dst_bucket: String,
/// The destination object key.
#[arg(long)]
pub dst_key: String,
/// The storage class for the copied object (e.g. STANDARD, GLACIER).
#[arg(long)]
pub storage_class: Option<String>,
}
#[derive(Parser, Clone)]
pub struct RestoreArgs {
/// The name of the S3 bucket.
#[arg(short, long)]
pub bucket: String,
/// The object key.
#[arg(short, long)]
pub key: String,
/// The restore tier (e.g. Standard, Bulk, Expedited).
#[arg(long, default_value = "Standard")]
pub restore_tier: String,
/// The number of days to keep the restored copy available.
#[arg(long, default_value = "1")]
pub restore_days: i32,
}
/// Internal enum for dispatching single-object operations to `obj::run_obj`.
#[derive(Clone)]
pub enum ObjCommand {
Head(HeadArgs),
Download(DownloadArgs),
DownloadMultipart(DownloadMultipartArgs),
Upload(UploadArgs),
UploadMultipart(UploadMultipartArgs),
Delete(DeleteArgs),
Copy(CopyArgs),
Restore(RestoreArgs),
}
/// Arguments for CSV-driven batch operations.
#[derive(Parser, Clone)]
pub struct CsvArgs {
#[command(subcommand)]
pub command: CsvCommand,
/// The path to the CSV file.
pub source_path: String,
/// The zero-based column index in the CSV that holds the object key.
#[arg(short, long, default_value = "0")]
pub column_idx: usize,
/// Whether the CSV has a header row (the first row is skipped when reading keys).
#[arg(long, default_value = "false")]
pub has_header: bool,
/// Maximum number of keys to process in parallel (batch-level parallelism).
#[arg(short, long, default_value = "250")]
pub n_workers: usize,
}
#[derive(Subcommand, Clone)]
pub enum CsvCommand {
/// Get metadata (HEAD) for each key and print it.
Head {
/// The name of the S3 bucket.
#[arg(short, long)]
bucket: String,
/// The prefix prepended to each key from the CSV.
#[arg(short, long)]
prefix: String,
/// The suffix appended to each key from the CSV.
#[arg(short, long, default_value = "")]
suffix: String,
},
/// Download each key; preserve key path under the local directory.
Download {
/// The name of the S3 bucket.
#[arg(short, long)]
bucket: String,
/// The prefix prepended to each key from the CSV.
#[arg(short, long)]
prefix: String,
/// The suffix appended to each key from the CSV.
#[arg(short, long, default_value = "")]
suffix: String,
/// The local directory to download into (defaults to current directory).
#[arg(short, long, default_value = ".")]
local_dir: String,
},
/// Upload each key from files under the local directory.
Upload {
/// The name of the S3 bucket.
#[arg(short, long)]
bucket: String,
/// The prefix prepended to each key from the CSV.
#[arg(short, long)]
prefix: String,
/// The suffix appended to each key from the CSV.
#[arg(short, long, default_value = "")]
suffix: String,
/// The local directory to read files from (defaults to current directory).
#[arg(short, long, default_value = ".")]
local_dir: String,
/// The storage class (e.g. STANDARD, GLACIER).
#[arg(long)]
storage_class: Option<String>,
},
/// Delete each key.
Delete {
/// The name of the S3 bucket.
#[arg(short, long)]
bucket: String,
/// The prefix prepended to each key from the CSV.
#[arg(short, long)]
prefix: String,
/// The suffix appended to each key from the CSV.
#[arg(short, long, default_value = "")]
suffix: String,
},
/// Copy each key from source bucket to destination.
Copy {
/// The source bucket name.
#[arg(long)]
src_bucket: String,
/// The prefix prepended to each key for the source.
#[arg(long)]
src_prefix: String,
/// The suffix appended to each key for the source.
#[arg(long, default_value = "")]
src_suffix: String,
/// The destination bucket name.
#[arg(long)]
dst_bucket: String,
/// The prefix prepended to each key for the destination.
#[arg(long)]
dst_prefix: String,
/// The suffix appended to each key for the destination.
#[arg(long, default_value = "")]
dst_suffix: String,
/// The storage class for the copy (e.g. STANDARD, GLACIER).
#[arg(long)]
storage_class: Option<String>,
},
/// Restore each key from archival storage (e.g. Glacier).
Restore {
/// The name of the S3 bucket.
#[arg(short, long)]
bucket: String,
/// The prefix prepended to each key from the CSV.
#[arg(short, long)]
prefix: String,
/// The suffix appended to each key from the CSV.
#[arg(short, long, default_value = "")]
suffix: String,
/// The restore tier (e.g. Standard, Bulk, Expedited).
#[arg(long, default_value = "Standard")]
restore_tier: String,
/// The number of days to keep the restored copy available.
#[arg(long, default_value = "1")]
restore_days: i32,
},
}