-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmod.rs
More file actions
475 lines (372 loc) · 12.9 KB
/
mod.rs
File metadata and controls
475 lines (372 loc) · 12.9 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
use clap::{Parser, Subcommand, crate_description, crate_version};
use clap_complete::Shell;
use parquet::ComplexTypesMode;
pub mod hdf5;
pub mod tdms;
use hdf5::Hdf5Schema;
use std::path::PathBuf;
use tdms::TdmsFallbackMethod;
pub mod channel;
use channel::DataType;
pub mod export;
pub mod parquet;
pub mod time;
use time::TimeFormat;
#[derive(Parser)]
#[command(
version = crate_version!(),
about = crate_description!(),
)]
pub struct Args {
#[command(subcommand)]
pub cmd: Cmd,
/// The profile to use
#[arg(long, global = true)]
pub profile: Option<String>,
/// Disable TLS for non-cloud Sift environments
#[arg(long, global = true)]
pub disable_tls: bool,
}
#[derive(Subcommand)]
pub enum Cmd {
/// Manage Sift CLI configuration
#[command(subcommand)]
Config(ConfigCmd),
/// Manage shell autocompletions
#[command(subcommand)]
Completions(CompletionsCmd),
/// Export asset/run data from Sift
#[command(subcommand)]
Export(ExportCmd),
/// Import time series files into Sift
#[command(subcommand)]
Import(ImportCmd),
/// Ping the Sift API to verify credentials and connectivity
Ping,
}
#[derive(Subcommand)]
pub enum ExportCmd {
/// Export data for a run
Run(ExportRunArgs),
/// Export data for an asset
Asset(ExportAssetArgs),
}
#[derive(clap::Args)]
pub struct ExportRunArgs {
/// The name of the run
#[arg(short, long, group = "run_identifier")]
pub name: Option<String>,
/// The ID of the run
#[arg(short, long, group = "run_identifier")]
pub run_id: Option<String>,
/// The client key of the run
#[arg(short = 'k', long, group = "run_identifier")]
pub client_key: Option<String>,
#[command(flatten)]
pub common: ExportArgs,
}
#[derive(clap::Args)]
pub struct ExportAssetArgs {
/// The name of the asset
pub asset: String,
#[command(flatten)]
pub common: ExportArgs,
}
#[derive(clap::Args)]
pub struct ExportArgs {
/// The file to generate
#[arg(short, long)]
pub output: PathBuf,
/// File format for the output file
#[arg(short, long)]
pub format: export::Format,
/// Regular expression used to filter channels to include in the export
#[arg(short = 'x', long)]
pub channel_regex: Option<String>,
/// Name of channel to include in the export; can be specified multiple times
#[arg(short, long)]
pub channel: Vec<String>,
/// ID of channel to include in the export; can be specified multiple times
#[arg(long)]
pub channel_id: Vec<String>,
/// Regular expression used to filter calculated channels to include in the export
#[arg(long)]
pub calculated_channel_regex: Option<String>,
/// Name of calculated channel to include in the export; can be specified multiple times
#[arg(long)]
pub calculated_channel: Vec<String>,
/// ID of calculated channel to include in the export; can be specified multiple times
#[arg(long)]
pub calculated_channel_id: Vec<String>,
/// Start time in RFC 3339 format (required for asset exports)
#[arg(long)]
pub start: Option<String>,
/// Stop time in RFC 3339 format (required for asset exports)
#[arg(long)]
pub stop: Option<String>,
}
#[derive(Subcommand)]
pub enum CompletionsCmd {
/// Print completions for your shell
Print(CompletionsPrintArgs),
/// Attempts to automatically update this CLI's completions file for the current shell
Update,
}
#[derive(clap::Args)]
pub struct CompletionsPrintArgs {
/// The shell to print completions for. If empty the program will try to infer the user shell
/// by reading the "$SHELL" environment variable.
#[arg(short, long)]
pub shell: Option<Shell>,
}
#[derive(Subcommand)]
pub enum ImportCmd {
/// Import a CSV file into Sift. Unless manually specified all columns are inferred to type
/// string or double.
Csv(ImportCsvArgs),
/// Import a Parquet file into Sift.
#[command(subcommand)]
Parquet(ImportParquetCmd),
/// Import a Tdms file into Sift.
Tdms(ImportTdmsArgs),
/// Import an HDF5 file into Sift. Supported channel types: bool,
/// int8/16/32/64, uint8/16/32/64, float32, float64. Datasets with other
/// types will produce a client-side error.
Hdf5(ImportHdf5Args),
/// Import backup files generated by sift_stream into Sift.
#[command(name = "backups")]
Backup(BackupArgs),
}
#[derive(Subcommand)]
pub enum ConfigCmd {
/// Display the contents of the current config file
Show,
/// Show the path to the current config file
Where,
/// Create a new config file (fails if one already exists)
Create,
/// Update fields in the existing config file
Update(ConfigUpdateArgs),
}
#[derive(clap::Args)]
pub struct ConfigUpdateArgs {
/// Edit or create a profile interactively (ignores other flags)
#[arg(short, long)]
pub interactive: bool,
/// Base gRPC endpoint for Sift
#[arg(short, long)]
pub grpc_uri: Option<String>,
/// Base REST endpoint for Sift
#[arg(short, long)]
pub rest_uri: Option<String>,
/// API key used for authentication
#[arg(short = 'k', long)]
pub api_key: Option<String>,
}
#[derive(clap::Args)]
pub struct ImportCsvArgs {
/// Path to the CSV file to import
pub path: PathBuf,
/// Name of the asset this data belongs to
#[arg(short, long)]
pub asset: String,
/// Optional run name to associate with this import
#[arg(short, long)]
pub run: Option<String>,
/// Row number containing column headers (1-based)
#[arg(long, default_value_t = 1)]
pub header_row: usize,
/// Row number where data starts (1-based)
#[arg(long, default_value_t = 2)]
pub first_data_row: usize,
/// 1-based column indices to override; can appear multiple times
#[arg(short, long)]
pub channel_column: Vec<usize>,
/// Data type for each channel in `--channel-column`. Use `"infer"` to have the program infer
/// the data type which is useful when wanting to just specify `--unit` and/or `--description`
#[arg(short, long)]
pub data_type: Vec<DataType>,
/// Unit for each channel in `--channel-column` (can be empty)
#[arg(short, long)]
pub unit: Vec<String>,
/// Description for each channel in `--channel-column` (can be empty)
#[arg(short = 'n', long)]
pub description: Vec<String>,
/// Enum configuration pairs `<key,name>` (e.g. `"0,start|1,stop"`) for enum-type channels
#[arg(short, long)]
pub enum_config: Vec<String>,
/// Bit-field configuration triplets `<name,index,length>` (e.g. `"12v,0,4|led,4,4"`)
#[arg(short, long)]
pub bit_field_config: Vec<String>,
/// 1-based index of the time column
#[arg(short, long, default_value_t = 1)]
pub time_column: usize,
/// Time format used in the file
#[arg(short = 'f', long, default_value_t = TimeFormat::default())]
pub time_format: TimeFormat,
/// Start time (RFC3339) to use if time format is relative
#[arg(short = 's')]
pub relative_start_time: Option<String>,
/// Wait until the import finishes processing
#[arg(short, long)]
pub wait: bool,
/// Preview the parsed schema without uploading
#[arg(short, long)]
pub preview: bool,
}
#[derive(clap::Args)]
pub struct BackupArgs {
#[command(subcommand)]
pub cmd: Option<BackupCmd>,
#[command(flatten)]
pub import_args: ImportBackupArgs,
}
#[derive(Subcommand)]
pub enum BackupCmd {
/// List backup files in a directory
Ls(BackupLsArgs),
}
#[derive(clap::Args)]
pub struct BackupLsArgs {
/// Path to the directory containing backup files (defaults to your OS data directory if not provided)
pub path: Option<PathBuf>,
}
#[derive(clap::Args)]
pub struct ImportBackupArgs {
/// Path to the directory containing backup files to import (defaults to your OS data directory if not provided)
#[arg(short, long)]
pub path: Option<PathBuf>,
/// Delete backup files after successful upload
#[arg(short, long)]
pub cleanup: bool,
}
#[derive(clap::Args)]
pub struct CommonImportArgs {
/// Path to the file to import
pub path: PathBuf,
/// Name of the asset this data belongs to
#[arg(short, long)]
pub asset: String,
/// Optional run name to associate with this import
#[arg(short, long)]
pub run: Option<String>,
/// The id of an existing run to add this data to. Takes precedence over --run
#[arg(long)]
pub run_id: Option<String>,
/// Wait until the import finishes processing
#[arg(short, long)]
pub wait: bool,
/// Preview the parsed schema without uploading
#[arg(short, long)]
pub preview: bool,
}
#[derive(Subcommand)]
pub enum ImportParquetCmd {
/// A parquet file where every column is exclusive to a single channel except for the time
/// column
FlatDataset(FlatDatasetArgs),
}
#[derive(clap::Args)]
pub struct FlatDatasetArgs {
/// Path to the Parquet file to import
pub path: PathBuf,
/// Name of the asset this data belongs to
#[arg(short, long)]
pub asset: String,
/// Optional run name to associate with this import
#[arg(short, long)]
pub run: Option<String>,
/// Paths of data columns to import; can be specified multiple times
#[arg(short, long)]
pub channel_path: Vec<String>,
/// Data type for each channel in `--channel-path`. Use `"infer"` to have the program infer
/// the data type which is useful when wanting to just specify `--unit` and/or `--description`
#[arg(short, long)]
pub data_type: Vec<DataType>,
/// Unit for each channel in `--channel-path` (can be empty)
#[arg(short, long)]
pub unit: Vec<String>,
/// Description for each channel in `--channel-path` (can be empty)
#[arg(short = 'n', long)]
pub description: Vec<String>,
/// Enum configuration pairs `<key,name>` for enum-type channels
#[arg(short, long)]
pub enum_config: Vec<String>,
/// Bit-field configuration triplets `<index,name,bit_count>` for bit-field channels
#[arg(short, long)]
pub bit_field_config: Vec<String>,
/// Path to the time column
#[arg(short, long)]
pub time_path: String,
/// Time format used in the file
#[arg(short = 'f', long)]
pub time_format: TimeFormat,
/// Start time (RFC3339) to use if time format is relative
#[arg(short = 's', long)]
pub relative_start_time: Option<String>,
/// Strategy for handling complex types (maps, lists, structs)
#[arg(short = 'm', long, default_value_t = ComplexTypesMode::default())]
pub complex_types_mode: ComplexTypesMode,
/// Wait until the import finishes processing
#[arg(short, long)]
pub wait: bool,
/// Preview the parsed schema without uploading
#[arg(short, long)]
pub preview: bool,
}
#[derive(clap::Args)]
pub struct ImportTdmsArgs {
#[command(flatten)]
pub common: CommonImportArgs,
/// Optional override on start time
#[arg(long)]
pub start_time_override: Option<String>,
/// Fallback method for channels with missing timing information
#[arg(short, long, default_value = "fail-on-error")]
pub fallback_method: TdmsFallbackMethod,
/// Time format for the channels not using the TDMS timestamp type
#[arg(long)]
pub time_format: Option<TimeFormat>,
/// Relative start time for channels using a non standard time channel
#[arg(short = 's', long)]
pub relative_start_time: Option<String>,
/// If true, will import TDMS file properties to the run as metadata
#[arg(long)]
pub import_file_properties: bool,
}
#[derive(clap::Args)]
pub struct ImportHdf5Args {
#[command(flatten)]
pub common: CommonImportArgs,
/// Schema type for the HDF5 file. Supported channel types across all
/// schemas: bool, int8/16/32/64, uint8/16/32/64, float32, float64.
#[arg(long)]
pub schema: Hdf5Schema,
/// Time format used in the time dataset/column
#[arg(long)]
pub time_format: Option<TimeFormat>,
/// Start time (RFC3339) if the time format is relative
#[arg(short = 's', long)]
pub relative_start_time: Option<String>,
/// (two-d / compound) Index of the time column or field. Defaults to 0.
/// Mutually exclusive with --time-field and --time-name.
#[arg(
long,
conflicts_with_all = ["time_field", "time_name"],
help_heading = "Two-d schema options",
)]
pub time_index: Option<u64>,
/// (compound) Name of the time field. Mutually exclusive with --time-index
/// and --time-name.
#[arg(
long,
conflicts_with = "time_name",
help_heading = "Compound schema options"
)]
pub time_field: Option<String>,
/// (one-d) Leaf name of the time dataset when it doesn't match the default
/// auto-detected names (time, timestamp, timestamps, ts). Mutually exclusive
/// with --time-index and --time-field.
#[arg(long, help_heading = "One-d schema options")]
pub time_name: Option<String>,
}