Add the file parts subcommand.
This commit is contained in:
parent
6dc3aed5e8
commit
115b99ee66
|
@ -71,4 +71,23 @@ pub enum FileSubcommand {
|
|||
#[arg()]
|
||||
file: PathBuf,
|
||||
},
|
||||
|
||||
/// Extract parts of a file.
|
||||
Parts {
|
||||
/// Print the base name of the file (without the extension).
|
||||
#[arg(long, group = "part-to-print", default_value = "false")]
|
||||
basename: bool,
|
||||
|
||||
/// Print the directory the file is in.
|
||||
#[arg(long, group = "part-to-print", default_value = "false")]
|
||||
directory: bool,
|
||||
|
||||
/// Print the file extension (without the leading dot).
|
||||
#[arg(long, group = "part-to-print", default_value = "false")]
|
||||
extension: bool,
|
||||
|
||||
/// The file to include parts from.
|
||||
#[arg()]
|
||||
file: PathBuf,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use {
|
|||
logging::append_line_to_file,
|
||||
},
|
||||
chrono::{SecondsFormat, Utc},
|
||||
std::{ffi::OsStr, path::Path},
|
||||
};
|
||||
|
||||
/// Parse the CLI arguments and execute them.
|
||||
|
@ -36,6 +37,34 @@ pub fn run() {
|
|||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
FileSubcommand::Parts {
|
||||
basename,
|
||||
directory,
|
||||
extension,
|
||||
file,
|
||||
} => {
|
||||
if basename {
|
||||
print!(
|
||||
"{}",
|
||||
file.file_stem().and_then(OsStr::to_str).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
|
||||
if directory {
|
||||
print!(
|
||||
"{}",
|
||||
file.parent().and_then(Path::to_str).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
|
||||
if extension {
|
||||
print!(
|
||||
"{}",
|
||||
file.extension().and_then(OsStr::to_str).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Log { data_to_log, file } => {
|
||||
|
|
Loading…
Reference in New Issue