Initial GPL-3.0 Release (v1.0.0)
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
use clap::Parser;
|
||||
use sized::{run, Args, OutputFormat};
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use time::macros::format_description;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut writer: Box<dyn Write> = if let Some(path_arg) = &args.save {
|
||||
let output_path = if path_arg.to_string_lossy() == "_AUTO_" {
|
||||
let format = format_description!("[year][month][day]-[hour][minute][second]");
|
||||
let timestamp = OffsetDateTime::now_utc().format(format).unwrap();
|
||||
let dir_name = args.path.file_name().unwrap_or_default().to_string_lossy();
|
||||
let ext = match args.format {
|
||||
OutputFormat::Csv => "csv",
|
||||
OutputFormat::Json => "json",
|
||||
_ => "txt",
|
||||
};
|
||||
PathBuf::from(format!("{}_{}.{}", timestamp, dir_name, ext))
|
||||
} else {
|
||||
path_arg.clone()
|
||||
};
|
||||
|
||||
let f = std::fs::File::create(&output_path).expect("Failed to create output file");
|
||||
Box::new(f)
|
||||
} else {
|
||||
Box::new(std::io::stdout())
|
||||
};
|
||||
|
||||
run(args, &mut writer);
|
||||
}
|
||||
Reference in New Issue
Block a user