tiempo-rs/src/commands/sheet.rs

61 lines
1.3 KiB
Rust
Raw Normal View History

2021-07-01 23:44:38 -05:00
use std::convert::TryFrom;
use std::io::Write;
use clap::ArgMatches;
use chrono::{DateTime, Utc};
2021-07-01 23:44:38 -05:00
use crate::database::Database;
2021-07-14 12:37:08 -05:00
use crate::error::{Error, Result};
2021-07-01 23:44:38 -05:00
use crate::commands::Command;
use crate::config::Config;
use crate::commands::list::ListCommand;
2021-07-01 23:44:38 -05:00
#[derive(Default)]
pub struct Args {
sheet: Option<String>,
}
impl<'a> TryFrom<&'a ArgMatches<'a>> for Args {
2021-07-14 12:37:08 -05:00
type Error = Error;
2021-07-01 23:44:38 -05:00
2021-07-14 12:37:08 -05:00
fn try_from(matches: &'a ArgMatches) -> Result<Self> {
2021-07-01 23:44:38 -05:00
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<()>
2021-07-01 23:44:38 -05:00
where
D: Database,
O: Write,
E: Write,
{
2021-07-14 12:37:08 -05:00
if let Some(_sheet) = args.sheet {
// sheet given, switch to it
unimplemented!()
} else {
// call list
ListCommand::handle(Default::default(), db, out, err, config, now)
2021-07-14 12:37:08 -05:00
}
2021-07-01 23:44:38 -05:00
}
}
#[cfg(test)]
mod tests {
#[test]
fn switch_to_sheet() {
assert!(false);
}
#[test]
fn switch_to_sheet_already_in() {
assert!(false);
}
}