1
Fork 0

Add the file metadata subcommand.

This commit is contained in:
Bauke 2023-11-11 13:08:11 +01:00
parent 274973d09b
commit 38a828629e
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 29 additions and 1 deletions

View File

@ -98,6 +98,21 @@ pub enum FileSubcommand {
file: PathBuf,
},
/// Extract metadata of a file.
Metadata {
/// The chrono format string for dates, defaults to `%FT%T%z` (ISO 8601).
#[arg(long, default_value = "%FT%T%z")]
date_format: String,
/// Get the modified date (uses --date-format as the format string).
#[arg(long, default_value = "false")]
modified: bool,
/// The file to get the metadata of.
#[arg()]
file: PathBuf,
},
/// Extract parts of a file.
Parts {
/// Print the base name of the file (without the extension).

View File

@ -8,7 +8,7 @@ use {
},
logging::append_line_to_file,
},
chrono::{SecondsFormat, Utc},
chrono::{DateTime, Local, SecondsFormat, Utc},
std::{ffi::OsStr, path::Path},
};
@ -49,6 +49,19 @@ pub fn run() {
}
}
FileSubcommand::Metadata {
date_format,
modified,
file,
} => {
let metadata = std::fs::metadata(file).unwrap();
if modified {
let date_modified =
DateTime::<Local>::from(metadata.modified().unwrap());
print!("{}", date_modified.format(&date_format));
}
}
FileSubcommand::Parts {
basename,
directory,