diff options
Diffstat (limited to 'apps/cassiopeia/src/lib.rs')
-rw-r--r-- | apps/cassiopeia/src/lib.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/apps/cassiopeia/src/lib.rs b/apps/cassiopeia/src/lib.rs index 895110fe218d..7b4409c9689f 100644 --- a/apps/cassiopeia/src/lib.rs +++ b/apps/cassiopeia/src/lib.rs @@ -10,16 +10,18 @@ mod data; mod date; -mod error; mod format; -pub mod meta; mod time; mod timeline; +pub mod error; +pub mod meta; + pub use date::Date; pub use time::Time; use data::{Invoice, Session, TimeFile}; +use error::{ParseError, ParseResult}; use format::{ ir::{append_ir, clean_ir, IrStream, MakeIr}, ParseOutput, @@ -36,27 +38,22 @@ pub struct Cassiopeia { impl Cassiopeia { /// Load a cass file from disk, parsing it into a [`TimeFile`](crate::TimeFile) - pub fn load(path: &str) -> Option<Self> { + pub fn load(path: &str) -> ParseResult<Self> { let path = path.to_owned(); format::load_file(path.as_str()).map(|ParseOutput { tf, ir }| Self { path, tf, ir }) } - /// Store the modified time file back to disk - pub fn store(&self) -> Option<()> { - Some(()) - } - /// Start a new work session (with optional 15 minute rounding) - pub fn start(&mut self, round: bool) -> Option<()> { - let delta = self.tf.timeline.start(Time::rounded(round)).ok()?; + pub fn start(&mut self, round: bool) -> ParseResult<()> { + let delta = self.tf.timeline.start(Time::rounded(round))?; clean_ir(&mut self.ir); append_ir(&mut self.ir, delta.make_ir()); format::write_file(self.path.as_str(), &mut self.ir) } /// Stop the existing work session (with optional 15 minute rounding) - pub fn stop(&mut self, round: bool) -> Option<()> { - let delta = self.tf.timeline.stop(Time::rounded(round)).ok()?; + pub fn stop(&mut self, round: bool) -> ParseResult<()> { + let delta = self.tf.timeline.stop(Time::rounded(round))?; clean_ir(&mut self.ir); append_ir(&mut self.ir, delta.make_ir()); format::write_file(self.path.as_str(), &mut self.ir) @@ -68,14 +65,14 @@ impl Cassiopeia { } /// Write out the file IR as is, updating only the header version - pub fn update(&mut self) -> Option<()> { + pub fn update(&mut self) -> ParseResult<()> { clean_ir(&mut self.ir); format::write_file(self.path.as_str(), &mut self.ir) } /// Collect statistics on previous work sessions - pub fn stat(&self) -> Option<String> { - None + pub fn stat(&self) -> ParseResult<String> { + todo!() } } @@ -102,6 +99,7 @@ impl Cassiopeia { /// .client("ACME".into()) /// .run(); /// ``` +#[allow(unused)] pub struct Invoicer<'cass> { tf: &'cass mut Cassiopeia, generate: bool, @@ -143,13 +141,13 @@ impl<'cass> Invoicer<'cass> { Self { project, ..self } } - pub fn run(mut self) -> Option<()> { + pub fn run(mut self) -> ParseResult<()> { if self.generate { eprintln!("Integration with invoice(1) is currently not implemented. Sorry :("); - return None; + return Err(ParseError::Unknown); } - let delta = self.tf.tf.timeline.invoice(Date::today()).ok()?; + let delta = self.tf.tf.timeline.invoice(Date::today())?; clean_ir(&mut self.tf.ir); append_ir(&mut self.tf.ir, delta.make_ir()); format::write_file(self.tf.path.as_str(), &mut self.tf.ir) |