Add the file metadata subcommand.
This commit is contained in:
parent
274973d09b
commit
38a828629e
|
@ -98,6 +98,21 @@ pub enum FileSubcommand {
|
||||||
file: PathBuf,
|
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.
|
/// Extract parts of a file.
|
||||||
Parts {
|
Parts {
|
||||||
/// Print the base name of the file (without the extension).
|
/// Print the base name of the file (without the extension).
|
||||||
|
|
|
@ -8,7 +8,7 @@ use {
|
||||||
},
|
},
|
||||||
logging::append_line_to_file,
|
logging::append_line_to_file,
|
||||||
},
|
},
|
||||||
chrono::{SecondsFormat, Utc},
|
chrono::{DateTime, Local, SecondsFormat, Utc},
|
||||||
std::{ffi::OsStr, path::Path},
|
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 {
|
FileSubcommand::Parts {
|
||||||
basename,
|
basename,
|
||||||
directory,
|
directory,
|
||||||
|
|
Loading…
Reference in New Issue