solve some warnings in sheet

This commit is contained in:
Abraham Toriz 2021-07-14 12:37:08 -05:00
parent b20b138ea5
commit 067aeae0fe
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 11 additions and 34 deletions

View File

@ -4,7 +4,7 @@ use std::io::Write;
use clap::ArgMatches;
use crate::database::Database;
use crate::error;
use crate::error::{Error, Result};
use crate::commands::Command;
use crate::config::Config;
@ -14,9 +14,9 @@ pub struct Args {
}
impl<'a> TryFrom<&'a ArgMatches<'a>> for Args {
type Error = error::Error;
type Error = Error;
fn try_from(matches: &'a ArgMatches) -> Result<Self, Self::Error> {
fn try_from(matches: &'a ArgMatches) -> Result<Self> {
Ok(Args {
sheet: matches.value_of("sheet").map(|s| s.into()),
})
@ -28,47 +28,24 @@ 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) -> error::Result<()>
fn handle<D, O, E>(args: Args, _db: &mut D, _out: &mut O, _err: &mut E, _config: &Config) -> Result<()>
where
D: Database,
O: Write,
E: Write,
{
unimplemented!()
if let Some(_sheet) = args.sheet {
// sheet given, switch to it
unimplemented!()
} else {
// call list
Ok(())
}
}
}
#[cfg(test)]
mod tests {
use chrono::{Utc, TimeZone};
use crate::database::SqliteDatabase;
use crate::test_utils::PrettyString;
use super::*;
#[test]
fn list_sheets() {
let args = Default::default();
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
let config = Default::default();
db.entry_insert(Utc.ymd(2021, 1, 1).and_hms(0, 0, 0), None, None, "_archived".into()).unwrap();
db.entry_insert(Utc.ymd(2021, 1, 1).and_hms(0, 0, 0), None, None, "sheet1".into()).unwrap();
db.entry_insert(Utc.ymd(2021, 1, 1).and_hms(0, 0, 0), None, None, "sheet2".into()).unwrap();
db.entry_insert(Utc.ymd(2021, 1, 1).and_hms(0, 0, 0), None, None, "sheet3".into()).unwrap();
SheetCommand::handle(args, &mut db, &mut out, &mut err, &config).unwrap();
assert_eq!(PrettyString(&String::from_utf8_lossy(&out)), PrettyString(" Timesheet Running Today Total Time
sheet1 0:00:00 0:00:00 10:13:55
*sheet2 0:00:00 0:00:00 0:00:00
-sheet3 0:00:00 1:52:45 9:32:03
"));
}
#[test]
fn switch_to_sheet() {
assert!(false);