aboutsummaryrefslogtreecommitdiff
path: root/apps/cassiopeia/src/lib.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-12-15 19:41:48 +0000
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:49 +0100
commitb9c988f42504c2e4cfa0715ac8f2d2a0db591cad (patch)
tree4850aba3bc43b7b303c4a1a3b6dd64a3f85e1df5 /apps/cassiopeia/src/lib.rs
parent236cf191b90a428325c8c179d595d4b1cd36f776 (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.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)
}
}