diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 9c31c60..187d067 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -35,10 +35,7 @@ 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<()> { @@ -50,7 +47,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("{} {} ({:?})", uuid, issue.title(), issue.state); } } - Commands::New { description: Some(description), } => { @@ -58,54 +54,45 @@ 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.get_mut_issue(issue_id) { - Some(issue) => { - issue.edit_description()?; - } - None => { - 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.get_issue(issue_id) { - Some(issue) => { - println!("issue {}", issue_id); - println!("state: {:?}", issue.state); - if let Some(dependencies) = &issue.dependencies { - println!("dependencies: {:?}", dependencies); - } - println!(""); - println!("{}", issue.description); - } - None => { - return Err(anyhow::anyhow!("issue {} not found", issue_id)); - } - } - } - - 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(); + issue.edit_description()?; + } + None => { + println!("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) { + Some(issue) => { + println!("issue {}", issue_id); + println!("state {:?}", issue.state); + println!(""); + println!("{}", issue.description); + } + None => { + println!("issue {} not found", issue_id); + } + } + } + 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(); + match new_state { Some(s) => { issue.set_state(s.clone())?; @@ -117,9 +104,10 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("state: {}", current_state); } } + } None => { - return Err(anyhow::anyhow!("issue {} not found", issue_id)); + println!("issue {} not found", issue_id); } } } diff --git a/src/issues.rs b/src/issues.rs index 2e40930..a900ed6 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -35,14 +35,6 @@ 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)?;