tiempo-rs/src/commands/sheet.rs

61 lines
1.3 KiB
Rust

use std::convert::TryFrom;
use std::io::Write;
use clap::ArgMatches;
use chrono::{DateTime, Utc};
use crate::database::Database;
use crate::error::{Error, Result};
use crate::commands::Command;
use crate::config::Config;
use crate::commands::list::ListCommand;
#[derive(Default)]
pub struct Args {
sheet: Option<String>,
}
impl<'a> TryFrom<&'a ArgMatches<'a>> for Args {
type Error = Error;
fn try_from(matches: &'a ArgMatches) -> Result<Self> {
Ok(Args {
sheet: matches.value_of("sheet").map(|s| s.into()),
})
}
}
pub struct SheetCommand {}
impl<'a> Command<'a> for SheetCommand {
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,
{
if let Some(_sheet) = args.sheet {
// sheet given, switch to it
unimplemented!()
} else {
// call list
ListCommand::handle(Default::default(), db, out, err, config, now)
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn switch_to_sheet() {
assert!(false);
}
#[test]
fn switch_to_sheet_already_in() {
assert!(false);
}
}