diff --git a/src/commands.rs b/src/commands.rs index f6de1b7..8dce952 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -22,6 +22,7 @@ pub mod backend; pub mod kill; pub mod now; pub mod edit; +pub mod archive; pub trait Command<'a> { type Args: TryFrom<&'a ArgMatches<'a>>; diff --git a/src/commands/archive.rs b/src/commands/archive.rs new file mode 100644 index 0000000..7abcf9e --- /dev/null +++ b/src/commands/archive.rs @@ -0,0 +1,54 @@ +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>, + end: Option>, + grep: Option, + fake: bool, + sheet: Option, +} + +impl<'a> TryFrom<&'a ArgMatches<'a>> for Args { + type Error = Error; + + fn try_from(matches: &'a ArgMatches) -> Result { + 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(args: Args, db: &mut D, out: &mut O, err: &mut E, config: &Config, now: DateTime) -> Result<()> + where + D: Database, + O: Write, + E: Write, + { + unimplemented!() + } +} diff --git a/src/main.rs b/src/main.rs index 432e82c..8d69cfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use tiempo::commands::{ today::TodayCommand, yesterday::YesterdayCommand, week::WeekCommand, month::MonthCommand, list::ListCommand, out::OutCommand, resume::ResumeCommand, backend::BackendCommand, kill::KillCommand, - now::NowCommand, edit::EditCommand, + now::NowCommand, edit::EditCommand, archive::ArchiveCommand, }; fn error_trap(matches: ArgMatches) -> error::Result<()> { @@ -45,6 +45,7 @@ fn error_trap(matches: ArgMatches) -> error::Result<()> { ("kill", Some(matches)) => KillCommand::handle(matches.try_into()?, &mut conn, &mut out, &mut err, &config, now), ("now", Some(matches)) => NowCommand::handle(matches.try_into()?, &mut conn, &mut out, &mut err, &config, now), ("edit", Some(matches)) => EditCommand::handle(matches.try_into()?, &mut conn, &mut out, &mut err, &config, now), + ("archive", Some(matches)) => ArchiveCommand::handle(matches.try_into()?, &mut conn, &mut out, &mut err, &config, now), (cmd, _) => Err(error::Error::UnimplementedCommand(cmd.into())), } @@ -117,6 +118,10 @@ fn main() { .arg(start_arg.clone()) .arg(end_arg.clone()) .arg(grep_arg.clone()) + .arg(Arg::with_name("fake") + .short("f").long("fake") + .help("Don't actually archive the entries, just display them") + ) ) .subcommand(SubCommand::with_name("backend")