From 172055c48048289ff8b25ca8f439864b351342a9 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 12:53:05 -0600 Subject: [PATCH 1/8] always render issue UUIDs as 128 bit hex numbers --- src/git.rs | 4 ++-- src/issue.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/git.rs b/src/git.rs index bb17763..caa5e4b 100644 --- a/src/git.rs +++ b/src/git.rs @@ -213,7 +213,7 @@ mod tests { fn test_create_orphan_branch() { let rnd: u128 = rand::random(); let mut branch = std::string::String::from("entomologist-test-branch-"); - branch.push_str(&format!("{:0x}", rnd)); + branch.push_str(&format!("{:032x}", rnd)); create_orphan_branch(&branch).unwrap(); git_remove_branch(&branch).unwrap(); } @@ -228,7 +228,7 @@ mod tests { fn test_branch_exists_1() { let rnd: u128 = rand::random(); let mut branch = std::string::String::from("entomologist-missing-branch-"); - branch.push_str(&format!("{:0x}", rnd)); + branch.push_str(&format!("{:032x}", rnd)); let r = git_branch_exists(&branch).unwrap(); assert_eq!(r, false); } diff --git a/src/issue.rs b/src/issue.rs index 8031300..bb8594a 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -107,7 +107,7 @@ impl Issue { pub fn new(dir: &std::path::Path) -> Result { let mut issue_dir = std::path::PathBuf::from(dir); let rnd: u128 = rand::random(); - issue_dir.push(&format!("{:0x}", rnd)); + issue_dir.push(&format!("{:032x}", rnd)); std::fs::create_dir(&issue_dir)?; Ok(Self { description: String::from(""), // FIXME: kind of bogus to use the empty string as None From ed1b4488b2ef09cf10181bb76fbbca95e399818c Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 12:56:59 -0600 Subject: [PATCH 2/8] 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)] From a6d2f7d1e83a0f86fd52324b73417925c27d8fc1 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 13:07:55 -0600 Subject: [PATCH 3/8] 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; From 0f46eb78172a75a8fca80f119fbe912293f9a1d1 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 13:28:26 -0600 Subject: [PATCH 4/8] 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(()) From bcc8ba4f2147879c95f73913fb69a74ca1141412 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Mon, 7 Jul 2025 16:49:25 -0600 Subject: [PATCH 5/8] 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); From b789a3d293cb73bdc293c3e3422b5b4ae48fead2 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 15:30:46 -0600 Subject: [PATCH 6/8] ent show: show dependencies, if any --- src/bin/ent/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 187d067..b2eaee2 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -77,7 +77,10 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( match issues.issues.get(issue_id) { Some(issue) => { println!("issue {}", issue_id); - println!("state {:?}", issue.state); + println!("state: {:?}", issue.state); + if let Some(dependencies) = &issue.dependencies { + println!("dependencies: {:?}", dependencies); + } println!(""); println!("{}", issue.description); } From 4307ab98a0bede7ed11ba1da176d6fad53b7ceb5 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 16:14:19 -0600 Subject: [PATCH 7/8] better interface to looking up issue --- src/bin/ent/main.rs | 4 ++-- src/issues.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index b2eaee2..83ebb7f 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -62,7 +62,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( Commands::Edit { issue_id } => { let mut issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; - match issues.issues.get_mut(issue_id) { + match issues.get_mut_issue(issue_id) { Some(issue) => { issue.edit_description()?; } @@ -74,7 +74,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( Commands::Show { issue_id } => { let issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; - match issues.issues.get(issue_id) { + match issues.get_issue(issue_id) { Some(issue) => { println!("issue {}", issue_id); println!("state: {:?}", issue.state); diff --git a/src/issues.rs b/src/issues.rs index a900ed6..2e40930 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -35,6 +35,14 @@ impl Issues { self.issues.insert(uuid, issue); } + pub fn get_issue(&self, issue_id: &str) -> Option<&crate::issue::Issue> { + self.issues.get(issue_id) + } + + pub fn get_mut_issue(&mut self, issue_id: &str) -> Option<&mut crate::issue::Issue> { + self.issues.get_mut(issue_id) + } + fn parse_config(&mut self, config_path: &std::path::Path) -> Result<(), ReadIssuesError> { let config_contents = std::fs::read_to_string(config_path)?; let config: Config = toml::from_str(&config_contents)?; From 035c150f4cc9aa271c2cf2a4b380970bfa8454e0 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 16:14:42 -0600 Subject: [PATCH 8/8] ent: better error reporting --- src/bin/ent/main.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 83ebb7f..9c31c60 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -35,7 +35,10 @@ enum Commands { Show { issue_id: String }, /// Modify the state of an issue - State { issue_id: String, new_state: Option }, + State { + issue_id: String, + new_state: Option, + }, } fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { @@ -47,6 +50,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("{} {} ({:?})", uuid, issue.title(), issue.state); } } + Commands::New { description: Some(description), } => { @@ -54,11 +58,13 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( issue.set_description(description)?; println!("created new issue '{}'", issue.title()); } + Commands::New { description: None } => { let mut issue = entomologist::issue::Issue::new(issues_dir)?; issue.edit_description()?; println!("created new issue '{}'", issue.title()); } + Commands::Edit { issue_id } => { let mut issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; @@ -67,10 +73,11 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( issue.edit_description()?; } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } } + Commands::Show { issue_id } => { let issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; @@ -85,17 +92,20 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("{}", issue.description); } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } } - Commands::State { issue_id, new_state } => { + + 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 current_state = issue.state.clone(); - + let current_state = issue.state.clone(); match new_state { Some(s) => { issue.set_state(s.clone())?; @@ -107,10 +117,9 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("state: {}", current_state); } } - } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } }