tiempo-rs/src/commands/archive.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

2021-08-09 10:13:51 -05:00
use std::convert::TryFrom;
use std::io::Write;
use clap::ArgMatches;
use chrono::{DateTime, Utc};
use regex::Regex;
use crate::database::{Database, DBVersion};
use crate::error::{Error, Result};
use crate::commands::Command;
use crate::config::Config;
use crate::timeparse::parse_time;
use crate::old::{entries_or_warning, time_or_warning, warn_if_needed};
use crate::formatters::text;
use crate::editor;
use crate::regex::parse_regex;
#[derive(Default)]
pub struct Args {
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
grep: Option<Regex>,
fake: bool,
sheet: Option<String>,
}
impl<'a> TryFrom<&'a ArgMatches<'a>> for Args {
type Error = Error;
fn try_from(matches: &'a ArgMatches) -> Result<Self> {
Ok(Args {
start: matches.value_of("start").map(|s| parse_time(s)).transpose()?,
end: matches.value_of("end").map(|s| parse_time(s)).transpose()?,
grep: matches.value_of("grep").map(parse_regex).transpose()?,
fake: matches.is_present("fake"),
sheet: matches.value_of("sheet").map(|s| s.to_owned()),
})
}
}
pub struct ArchiveCommand {}
impl<'a> Command<'a> for ArchiveCommand {
type Args = Args;
fn handle<D, O, E>(args: Args, db: &mut D, out: &mut O, err: &mut E, config: &Config, now: DateTime<Utc>) -> Result<()>
where
D: Database,
O: Write,
E: Write,
{
unimplemented!()
}
}