From ed1b4488b2ef09cf10181bb76fbbca95e399818c Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 12:56:59 -0600 Subject: [PATCH 1/4] issue.rs: add state getter/setter --- src/issue.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/issue.rs b/src/issue.rs index 8031300..d3ecf3d 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -4,7 +4,7 @@ use std::str::FromStr; #[cfg(feature = "log")] use log::debug; -#[derive(Debug, PartialEq, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq, serde::Deserialize)] /// These are the states an issue can be in. pub enum State { New, @@ -157,6 +157,23 @@ impl Issue { None => self.description.as_str(), } } + + pub fn set_state(&mut self, new_state: State) -> Result<(), IssueError> { + let mut state_filename = std::path::PathBuf::from(&self.dir); + state_filename.push("state"); + let mut state_file = std::fs::File::create(&state_filename)?; + write!(state_file, "{}", new_state)?; + crate::git::git_commit_file(&state_filename)?; + Ok(()) + } + + pub fn read_state(&mut self) -> Result<(), IssueError> { + let mut state_filename = std::path::PathBuf::from(&self.dir); + state_filename.push("state"); + let state_string = std::fs::read_to_string(state_filename)?; + self.state = State::from_str(state_string.trim())?; + Ok(()) + } } #[cfg(test)] -- 2.47.3 From a6d2f7d1e83a0f86fd52324b73417925c27d8fc1 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 13:07:55 -0600 Subject: [PATCH 2/4] issue.rs: add fmt::Display for State --- src/issue.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/issue.rs b/src/issue.rs index d3ecf3d..61f7072 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -1,3 +1,4 @@ +use core::fmt; use std::io::Write; use std::str::FromStr; @@ -62,6 +63,21 @@ impl FromStr for State { } } +impl fmt::Display for State { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let fmt_str = match self { + State::New => "new", + State::Backlog => "backlog", + State::Blocked => "blocked", + State::InProgress => "inprogress", + State::Done => "done", + State::WontDo => "wontdo", + + }; + write!(f, "{fmt_str}") + } +} + impl Issue { pub fn new_from_dir(dir: &std::path::Path) -> Result { let mut description: Option = None; -- 2.47.3 From 0f46eb78172a75a8fca80f119fbe912293f9a1d1 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 13:28:26 -0600 Subject: [PATCH 3/4] add State command to CLI --- src/bin/ent/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index d26dc3c..6a3c9f0 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -1,5 +1,6 @@ use clap::Parser; +use entomologist::issue::State; #[cfg(feature = "log")] use simple_logger; @@ -32,6 +33,9 @@ enum Commands { /// Show the full description of an issue. Show { issue_id: String }, + + /// Modify the state of an issue + State { issue_id: String, new_state: State }, } fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { @@ -82,6 +86,20 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( } } } + Commands::State { issue_id, new_state } => { + let mut issues = + entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; + match issues.issues.get_mut(issue_id) { + Some(issue) => { + let old_state = issue.state.clone(); + issue.set_state(new_state.clone())?; + println!("issue {}: state {} -> {}", issue_id, old_state, new_state); + } + None => { + println!("issue {} not found", issue_id); + } + } + } } Ok(()) -- 2.47.3 From bcc8ba4f2147879c95f73913fb69a74ca1141412 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 16:49:25 -0600 Subject: [PATCH 4/4] update CLI to have optional state control --- src/bin/ent/main.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 6a3c9f0..187d067 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -35,7 +35,7 @@ enum Commands { Show { issue_id: String }, /// Modify the state of an issue - State { issue_id: String, new_state: State }, + State { issue_id: String, new_state: Option }, } fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { @@ -91,9 +91,20 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; match issues.issues.get_mut(issue_id) { Some(issue) => { - let old_state = issue.state.clone(); - issue.set_state(new_state.clone())?; - println!("issue {}: state {} -> {}", issue_id, old_state, new_state); + let current_state = issue.state.clone(); + + match new_state { + Some(s) => { + issue.set_state(s.clone())?; + println!("issue: {}", issue_id); + println!("state: {} -> {}", current_state, s); + } + None => { + println!("issue: {}", issue_id); + println!("state: {}", current_state); + } + } + } None => { println!("issue {} not found", issue_id); -- 2.47.3