Specify range on command line
Also use the current date as base for the range if no date is specified. Previously, it was all hardcoded.
This commit is contained in:
parent
494f1976c6
commit
e2aa7c1a29
1 changed files with 15 additions and 5 deletions
20
src/cli.rs
20
src/cli.rs
|
|
@ -1,7 +1,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::{Duration, NaiveDate};
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
|
@ -19,6 +19,15 @@ pub struct Opt {
|
||||||
/// File to load
|
/// File to load
|
||||||
#[structopt(short, long, parse(from_os_str))]
|
#[structopt(short, long, parse(from_os_str))]
|
||||||
file: Option<PathBuf>,
|
file: Option<PathBuf>,
|
||||||
|
/// Overwrite the current date
|
||||||
|
#[structopt(short, long)]
|
||||||
|
date: Option<NaiveDate>,
|
||||||
|
/// How many days to include before the current date
|
||||||
|
#[structopt(short, long, default_value = "3")]
|
||||||
|
before: u32,
|
||||||
|
/// How many days to include after the current date
|
||||||
|
#[structopt(short, long, default_value = "13")]
|
||||||
|
after: u32,
|
||||||
/// Number of the entry to view or edit
|
/// Number of the entry to view or edit
|
||||||
entry: Option<usize>,
|
entry: Option<usize>,
|
||||||
#[structopt(subcommand)]
|
#[structopt(subcommand)]
|
||||||
|
|
@ -28,7 +37,7 @@ pub struct Opt {
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Shows entries in a range, or a single entry if one is specified
|
/// Shows entries in a range, or a single entry if one is specified
|
||||||
/// (default)
|
/// [default]
|
||||||
Show,
|
Show,
|
||||||
/// Marks an entry as done (requires entry)
|
/// Marks an entry as done (requires entry)
|
||||||
Done,
|
Done,
|
||||||
|
|
@ -50,11 +59,12 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
let mut files = Files::load(&file)?;
|
let mut files = Files::load(&file)?;
|
||||||
let now = files.now().naive_local();
|
let now = files.now().naive_local();
|
||||||
|
|
||||||
|
let range_date = opt.date.unwrap_or_else(|| now.date());
|
||||||
let range = DateRange::new(
|
let range = DateRange::new(
|
||||||
NaiveDate::from_ymd(2021, 12, 12 - 3),
|
range_date - Duration::days(opt.before.into()),
|
||||||
NaiveDate::from_ymd(2021, 12, 12 + 13),
|
range_date + Duration::days(opt.after.into()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.expect("determine range");
|
||||||
|
|
||||||
let entries = files.eval(EntryMode::Relevant, range)?;
|
let entries = files.eval(EntryMode::Relevant, range)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue