start the archive command
This commit is contained in:
parent
3a1ef47b21
commit
d7e98e51a3
|
@ -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>>;
|
||||
|
|
|
@ -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<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!()
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue