teach ent edit to edit Comments as well as Issues

This commit is contained in:
Sebastian Kuzminsky 2025-07-11 14:24:57 -06:00
parent 928e592722
commit 65316da0bd

View file

@ -32,8 +32,8 @@ enum Commands {
/// Create a new issue. /// Create a new issue.
New { description: Option<String> }, New { description: Option<String> },
/// Edit the description of an issue. /// Edit the description of an Issue or a Comment.
Edit { issue_id: String }, Edit { uuid: String },
/// Show the full description of an issue. /// Show the full description of an issue.
Show { issue_id: String }, Show { issue_id: String },
@ -231,25 +231,39 @@ fn handle_command(
} }
} }
Commands::Edit { issue_id } => { Commands::Edit { uuid } => {
let issues_database = let issues_database =
make_issues_database(issues_database_source, IssuesDatabaseAccess::ReadWrite)?; make_issues_database(issues_database_source, IssuesDatabaseAccess::ReadWrite)?;
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?; let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
match issues.get_mut_issue(issue_id) { if let Some(issue) = issues.get_mut_issue(uuid) {
Some(issue) => match issue.edit_description() { match issue.edit_description() {
Err(entomologist::issue::IssueError::EmptyDescription) => { Err(entomologist::issue::IssueError::EmptyDescription) => {
println!("aborted issue edit"); println!("aborted issue edit");
return Ok(()); return Ok(());
} }
Err(e) => { Err(e) => return Err(e.into()),
return Err(e.into()); Ok(()) => return Ok(()),
}
Ok(()) => (),
},
None => {
return Err(anyhow::anyhow!("issue {} not found", issue_id));
} }
} }
// No issue by that ID, check all the comments.
for (_, issue) in issues.issues.iter_mut() {
for comment in issue.comments.iter_mut() {
if comment.uuid == *uuid {
match comment.edit_description() {
Err(entomologist::comment::CommentError::EmptyDescription) => {
println!("aborted comment edit");
return Ok(());
}
Err(e) => return Err(e.into()),
Ok(()) => return Ok(()),
}
}
}
}
return Err(anyhow::anyhow!(
"no issue or comment with uuid {} found",
uuid
));
} }
Commands::Show { issue_id } => { Commands::Show { issue_id } => {