diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-12-13 12:08:55 +0000 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-21 05:19:49 +0100 |
commit | 236cf191b90a428325c8c179d595d4b1cd36f776 (patch) | |
tree | 5d6c67cb0b7ef980aad47ee35e264b4dfdb5422d /apps/cassiopeia/src/lib.rs | |
parent | 4c97f3208a0ba185264a169e01d0b0d922266ea6 (diff) |
cassiopeia: changing parser output to more generic IR structure
This allows a few things: a, it's a persistant format that we can
mirror to disk again, AND can adapt because all type information is
known, and it allows for new entries to be added to the IR more
easily, without having to worry about exact formatting, or
re-inferring order from the TimeFile abstraction.
Diffstat (limited to 'apps/cassiopeia/src/lib.rs')
-rw-r--r-- | apps/cassiopeia/src/lib.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/apps/cassiopeia/src/lib.rs b/apps/cassiopeia/src/lib.rs index 1ea50fb8bc17..d4ebf5355bb9 100644 --- a/apps/cassiopeia/src/lib.rs +++ b/apps/cassiopeia/src/lib.rs @@ -9,28 +9,32 @@ //! https://git.spacekookie.de/kookienomicon/tree/apps/cassiopeia mod data; +mod date; mod format; pub mod meta; mod time; -pub use data::{Session, TimeFile}; +pub use date::Date; pub use format::load_file; +pub use time::Time; -/// A state handler for all cass interactions +use data::{Invoice, Session, TimeFile}; +use format::{ir, IrStream, ParseOutput}; + +/// A state handler and primary API for all cass interactions +/// /// -/// This could be a stateless API, but I like being able to refer to -/// fields that need to be saved for later here. This API wraps -/// around [`TimeFile`](crate::TimeFile), so that you don't have to! ✨ pub struct Cassiopeia { path: String, tf: TimeFile, + ir: IrStream, } impl Cassiopeia { /// Load a cass file from disk, parsing it into a [`TimeFile`](crate::TimeFile) pub fn load(path: &str) -> Option<Self> { let path = path.to_owned(); - load_file(path.as_str()).map(|tf| Self { path, tf }) + load_file(path.as_str()).map(|ParseOutput { tf, ir }| Self { path, tf, ir }) } /// Store the modified time file back to disk @@ -40,11 +44,15 @@ impl Cassiopeia { /// Start a new work session (with optional 15 minute rounding) pub fn start(&mut self, round: bool) -> Option<()> { - self.tf.start(round) + self.tf.start(round)?; + + Some(()) } /// Stop the existing work session (with optional 15 minute rounding) pub fn stop(&mut self, round: bool) -> Option<()> { + self.tf.stop(round)?; + Some(()) } @@ -96,7 +104,7 @@ impl<'cass> Invoicer<'cass> { } } - /// S + /// Enable the invoice generation feature pub fn generate(self) -> Self { Self { generate: true, @@ -120,10 +128,12 @@ impl<'cass> Invoicer<'cass> { pub fn run(self) -> Option<()> { if self.generate { - eprintln!("Integration with invoice(1) is currently not implemented. Sorry :()"); + eprintln!("Integration with invoice(1) is currently not implemented. Sorry :("); return None; } - None + self.tf.tf.invoice()?; + + Some(()) } } |