Merge pull request 'minor-ent-fixes' (#8) from minor-ent-fixes into main

Reviewed-on: #8
Reviewed-by: sigil-03 <sigil@glyphs.tech>
This commit is contained in:
sigil-03 2025-07-07 18:57:29 -06:00
commit 5df03337d9
2 changed files with 31 additions and 11 deletions

View file

@ -35,7 +35,10 @@ enum Commands {
Show { issue_id: String },
/// 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<()> {
@ -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,45 +58,54 @@ 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))?;
match issues.issues.get_mut(issue_id) {
match issues.get_mut_issue(issue_id) {
Some(issue) => {
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))?;
match issues.issues.get(issue_id) {
match issues.get_issue(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);
}
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())?;
@ -104,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));
}
}
}

View file

@ -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)?;