Implement done command
This commit is contained in:
parent
0de89bd424
commit
b476a95afb
6 changed files with 67 additions and 20 deletions
16
src/files.rs
16
src/files.rs
|
|
@ -5,7 +5,7 @@ use std::{fs, io, result};
|
|||
use chrono::{DateTime, Utc};
|
||||
use tzfile::Tz;
|
||||
|
||||
use self::commands::{Command, File};
|
||||
use self::commands::{Command, Done, File};
|
||||
|
||||
pub mod commands;
|
||||
mod format;
|
||||
|
|
@ -79,6 +79,9 @@ pub enum Error {
|
|||
file2: PathBuf,
|
||||
tz2: String,
|
||||
},
|
||||
// TODO Add span or something similar for a nicer error message
|
||||
#[error("Not a task")]
|
||||
NotATask,
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
|
@ -161,6 +164,7 @@ impl Files {
|
|||
pub fn save(&self) -> Result<()> {
|
||||
for file in &self.files {
|
||||
if file.dirty {
|
||||
println!("Saving file {:?}", file.path);
|
||||
Self::save_file(&file.path, &file.file)?;
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +189,16 @@ impl Files {
|
|||
&self.files[source.file].file.commands[source.command]
|
||||
}
|
||||
|
||||
pub fn add_done(&mut self, source: Source, done: Done) -> Result<()> {
|
||||
let file = &mut self.files[source.file];
|
||||
match &mut file.file.commands[source.command] {
|
||||
Command::Task(t) => t.done.push(done),
|
||||
Command::Note(_) => return Err(Error::NotATask),
|
||||
}
|
||||
file.dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn commands(&self) -> Vec<SourcedCommand<'_>> {
|
||||
let mut result = vec![];
|
||||
for (file_index, file) in self.files.iter().enumerate() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue