Specify --date via CliDate
This commit is contained in:
parent
0484eda859
commit
ff642cc8c8
1 changed files with 10 additions and 12 deletions
22
src/cli.rs
22
src/cli.rs
|
|
@ -28,8 +28,8 @@ pub struct Opt {
|
|||
#[structopt(short, long, parse(from_os_str))]
|
||||
file: Option<PathBuf>,
|
||||
/// Overwrite the current date
|
||||
#[structopt(short, long)]
|
||||
date: Option<NaiveDate>,
|
||||
#[structopt(short, long, default_value = "t")]
|
||||
date: String,
|
||||
/// Range of days to focus on
|
||||
#[structopt(short, long, default_value = "t-2d--t+13d")]
|
||||
range: String,
|
||||
|
|
@ -79,15 +79,6 @@ fn load_files(opt: &Opt, files: &mut Files) -> result::Result<(), files::Error>
|
|||
files.load(&file)
|
||||
}
|
||||
|
||||
fn find_now(opt: &Opt, files: &Files) -> NaiveDateTime {
|
||||
let now = files.now().naive_local();
|
||||
if let Some(date) = opt.date {
|
||||
date.and_time(now.time())
|
||||
} else {
|
||||
now
|
||||
}
|
||||
}
|
||||
|
||||
fn find_entries(files: &Files, range: DateRange) -> Result<Vec<Entry>, Error<FileSource>> {
|
||||
Ok(files.eval(EntryMode::Relevant, range)?)
|
||||
}
|
||||
|
|
@ -188,7 +179,14 @@ pub fn run() {
|
|||
process::exit(1);
|
||||
}
|
||||
|
||||
let now = find_now(&opt, &files);
|
||||
let now = files.now().naive_local();
|
||||
let today = match parse_eval_arg("--date", &opt.date, |date: CliDate| {
|
||||
date.eval((), now.date())
|
||||
}) {
|
||||
Some(date) => date,
|
||||
None => process::exit(1),
|
||||
};
|
||||
let now = today.and_time(now.time());
|
||||
|
||||
let range = match parse_eval_arg("--range", &opt.range, |range: CliRange| {
|
||||
range.eval((), now.date())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue