Compare commits

...

4 commits

Author SHA1 Message Date
5df03337d9 Merge pull request 'minor-ent-fixes' (#8) from minor-ent-fixes into main
Reviewed-on: #8
Reviewed-by: sigil-03 <sigil@glyphs.tech>
2025-07-07 18:57:29 -06:00
035c150f4c ent: better error reporting 2025-07-07 18:17:34 -06:00
4307ab98a0 better interface to looking up issue 2025-07-07 18:13:46 -06:00
b789a3d293 ent show: show dependencies, if any 2025-07-07 18:13:46 -06:00
2 changed files with 31 additions and 11 deletions

View file

@ -35,7 +35,10 @@ enum Commands {
Show { issue_id: String }, Show { issue_id: String },
/// Modify the state of an issue /// Modify the state of an issue
State { issue_id: String, new_state: Option<State> }, State {
issue_id: String,
new_state: Option<State>,
},
} }
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { 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); println!("{} {} ({:?})", uuid, issue.title(), issue.state);
} }
} }
Commands::New { Commands::New {
description: Some(description), description: Some(description),
} => { } => {
@ -54,45 +58,54 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
issue.set_description(description)?; issue.set_description(description)?;
println!("created new issue '{}'", issue.title()); println!("created new issue '{}'", issue.title());
} }
Commands::New { description: None } => { Commands::New { description: None } => {
let mut issue = entomologist::issue::Issue::new(issues_dir)?; let mut issue = entomologist::issue::Issue::new(issues_dir)?;
issue.edit_description()?; issue.edit_description()?;
println!("created new issue '{}'", issue.title()); println!("created new issue '{}'", issue.title());
} }
Commands::Edit { issue_id } => { Commands::Edit { issue_id } => {
let mut issues = let mut issues =
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; 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) => { Some(issue) => {
issue.edit_description()?; issue.edit_description()?;
} }
None => { None => {
println!("issue {} not found", issue_id); return Err(anyhow::anyhow!("issue {} not found", issue_id));
} }
} }
} }
Commands::Show { issue_id } => { Commands::Show { issue_id } => {
let issues = let issues =
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; 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) => { Some(issue) => {
println!("issue {}", issue_id); println!("issue {}", issue_id);
println!("state {:?}", issue.state); println!("state: {:?}", issue.state);
if let Some(dependencies) = &issue.dependencies {
println!("dependencies: {:?}", dependencies);
}
println!(""); println!("");
println!("{}", issue.description); println!("{}", issue.description);
} }
None => { 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 = let mut issues =
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?;
match issues.issues.get_mut(issue_id) { match issues.issues.get_mut(issue_id) {
Some(issue) => { Some(issue) => {
let current_state = issue.state.clone(); let current_state = issue.state.clone();
match new_state { match new_state {
Some(s) => { Some(s) => {
issue.set_state(s.clone())?; issue.set_state(s.clone())?;
@ -104,10 +117,9 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
println!("state: {}", current_state); println!("state: {}", current_state);
} }
} }
} }
None => { None => {
println!("issue {} not found", issue_id); return Err(anyhow::anyhow!("issue {} not found", issue_id));
} }
} }
} }

View file

@ -35,6 +35,14 @@ impl Issues {
self.issues.insert(uuid, issue); 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> { fn parse_config(&mut self, config_path: &std::path::Path) -> Result<(), ReadIssuesError> {
let config_contents = std::fs::read_to_string(config_path)?; let config_contents = std::fs::read_to_string(config_path)?;
let config: Config = toml::from_str(&config_contents)?; let config: Config = toml::from_str(&config_contents)?;