diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-12-15 19:41:48 +0000 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-15 19:41:48 +0000 |
commit | d7fff0b83e0bc931e29a3e64c1f978a09a3fd429 (patch) | |
tree | 6328b2700e74fae191967391c9f8f6b054c36c1a /apps/cassiopeia/src/lib.rs | |
parent | bfe67afa8a9238bd2a3bfdc9079917c81c8cfef3 (diff) |
cassiopeia: finishing up version 0.3.0
This commit does kind of a lot to get cass(1) over the finish line.
For one it implements all the CLI functions (well, almost all) with
their respective parameters, and also creates a new `gen` module which
uses the IR stream to generate a new file based on the old one, while
updating header fields that need to be updated (currently only
`version`).
This version does nothing with the actual header values, and probably
has a lot of bugs. More documentation will follow in future
cassiopeia commits.
Diffstat (limited to 'apps/cassiopeia/src/lib.rs')
-rw-r--r-- | apps/cassiopeia/src/lib.rs | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/apps/cassiopeia/src/lib.rs b/apps/cassiopeia/src/lib.rs index d4ebf5355bb9..e391c695237e 100644 --- a/apps/cassiopeia/src/lib.rs +++ b/apps/cassiopeia/src/lib.rs @@ -15,11 +15,13 @@ pub mod meta; mod time; pub use date::Date; -pub use format::load_file; pub use time::Time; use data::{Invoice, Session, TimeFile}; -use format::{ir, IrStream, ParseOutput}; +use format::{ + ir::{append_ir, clean_ir, IrStream, MakeIr}, + ParseOutput, +}; /// A state handler and primary API for all cass interactions /// @@ -34,7 +36,7 @@ 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(|ParseOutput { tf, ir }| Self { path, tf, ir }) + format::load_file(path.as_str()).map(|ParseOutput { tf, ir }| Self { path, tf, ir }) } /// Store the modified time file back to disk @@ -44,22 +46,30 @@ impl Cassiopeia { /// Start a new work session (with optional 15 minute rounding) pub fn start(&mut self, round: bool) -> Option<()> { - self.tf.start(round)?; - - Some(()) + let s = self.tf.start(round)?; + clean_ir(&mut self.ir); + append_ir(&mut self.ir, s.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<()> { - self.tf.stop(round)?; - - Some(()) + let s = self.tf.stop(round)?; + clean_ir(&mut self.ir); + append_ir(&mut self.ir, s.make_ir()); + format::write_file(self.path.as_str(), &mut self.ir) } /// Add an invoice block to the time file pub fn invoice<'slf>(&'slf mut self) -> Invoicer<'slf> { Invoicer::new(self) } + + /// Write out the file IR as is, updating only the header version + pub fn update(&mut self) -> Option<()> { + clean_ir(&mut self.ir); + format::write_file(self.path.as_str(), &mut self.ir) + } } /// An invoice generator builder @@ -126,14 +136,15 @@ impl<'cass> Invoicer<'cass> { Self { project, ..self } } - pub fn run(self) -> Option<()> { + pub fn run(mut self) -> Option<()> { if self.generate { eprintln!("Integration with invoice(1) is currently not implemented. Sorry :("); return None; } - self.tf.tf.invoice()?; - - Some(()) + let inv = self.tf.tf.invoice()?; + clean_ir(&mut self.tf.ir); + append_ir(&mut self.tf.ir, inv.make_ir()); + format::write_file(self.tf.path.as_str(), &mut self.tf.ir) } } |