aboutsummaryrefslogtreecommitdiff
path: root/apps/cassiopeia/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/cassiopeia/src/lib.rs')
-rw-r--r--apps/cassiopeia/src/lib.rs37
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)
}
}