diff options
author | dvvvvvv <dvvvvvv@dvvvvvv.com> | 2019-11-07 11:59:20 +0900 |
---|---|---|
committer | Abin Simon <abinsimon10@gmail.com> | 2019-12-16 16:41:50 +0530 |
commit | 698bc2ef3bd714144992f92e310a78d67e0e6048 (patch) | |
tree | b39c4a4a24388a9172a3929773922df4cb932919 /src | |
parent | c4c9ee01f4ab27359ed823ef2c7f3ee6b9a32df5 (diff) |
add date formatting validation
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -1,5 +1,6 @@ use clap::{App, Arg}; + pub fn build() -> App<'static, 'static> { App::new("lsd") .version(crate_version!()) @@ -134,6 +135,7 @@ pub fn build() -> App<'static, 'static> { .arg( Arg::with_name("date") .long("date") + .validator(validate_date_argument) .default_value("date") .multiple(true) .number_of_values(1) @@ -202,3 +204,16 @@ pub fn build() -> App<'static, 'static> { .help("Do not display files/directories with names matching the glob pattern(s)"), ) } + +fn validate_date_argument(arg: String) -> Result<(), String> { + use std::error::Error; + if arg.starts_with("+") { + time::now().strftime(&arg).map(drop).map_err(|err| err.description().to_string()) + } else if &arg == "date" { + Result::Ok(()) + } else if &arg == "relative" { + Result::Ok(()) + } else { + Result::Err("possible values: date, relative".to_owned()) + } +} |