tiempo-rs/src/commands.rs

71 lines
1.3 KiB
Rust
Raw Normal View History

2021-06-18 11:27:19 -05:00
use std::convert::TryFrom;
2021-08-25 14:30:27 -05:00
use std::io::{BufRead, Write};
2021-06-18 11:27:19 -05:00
use clap::ArgMatches;
use chrono::{DateTime, Utc};
2021-06-18 11:27:19 -05:00
use crate::error::Result;
use crate::database::Database;
2021-06-21 17:38:51 -05:00
use crate::config::Config;
2021-08-25 14:30:27 -05:00
use crate::io::Streams;
use crate::env::Env;
2021-06-18 11:27:19 -05:00
pub mod r#in;
pub mod display;
2021-07-06 22:52:20 -05:00
pub mod today;
2021-07-07 11:58:13 -05:00
pub mod yesterday;
2021-07-01 23:44:38 -05:00
pub mod sheet;
2021-07-07 13:44:19 -05:00
pub mod week;
2021-07-07 13:52:40 -05:00
pub mod month;
2021-07-14 12:37:45 -05:00
pub mod list;
2021-07-20 10:08:04 -05:00
pub mod out;
2021-07-26 16:55:24 -05:00
pub mod resume;
2021-07-26 20:07:11 -05:00
pub mod backend;
2021-07-30 17:55:19 -05:00
pub mod kill;
2021-08-02 18:45:54 -05:00
pub mod now;
pub mod edit;
2021-08-09 10:13:51 -05:00
pub mod archive;
2021-08-14 11:09:37 -05:00
pub mod configure;
2021-06-18 11:27:19 -05:00
2021-08-25 14:30:27 -05:00
pub struct Facts {
pub now: DateTime<Utc>,
pub config: Config,
pub env: Env,
}
impl Facts {
pub fn new() -> Facts {
Facts {
now: Utc::now(),
config: Default::default(),
env: Default::default(),
}
}
pub fn with_config(self, config: Config) -> Facts {
Facts {
config,
..self
}
}
pub fn with_now(self, now: DateTime<Utc>) -> Facts {
Facts {
now,
..self
}
}
}
impl Default for Facts {
fn default() -> Facts {
Facts::new()
}
}
2021-06-18 11:27:19 -05:00
pub trait Command<'a> {
type Args: TryFrom<&'a ArgMatches<'a>>;
2021-08-25 14:30:27 -05:00
fn handle<D: Database, I: BufRead, O: Write, E: Write>(args: Self::Args, streams: &mut Streams<D, I, O, E>, facts: &Facts) -> Result<()>;
2021-07-06 22:52:20 -05:00
}