implemented proper error handling, added README

This commit is contained in:
2026-06-26 12:30:19 +02:00
parent 649c08ad4b
commit 481e3a1dcc
8 changed files with 203 additions and 68 deletions
+32 -2
View File
@@ -1,3 +1,4 @@
use anyhow::{bail, Result};
use clap::Parser;
#[derive(Parser, Default, Debug)]
@@ -22,11 +23,40 @@ pub struct Arguments {
}
impl Arguments {
pub fn validate(&self) -> Result<(), Box<dyn std::error::Error>> {
pub fn validate(&self) -> Result<()> {
if self.action == "up" || self.action == "down" {
return Ok(());
}
Err("Action values are up or down.".into())
bail!("Action values are up or down.")
}
}
#[cfg(test)]
mod tests {
use super::*;
fn args_with_action(action: &str) -> Arguments {
Arguments {
project: "test".to_string(),
action: action.to_string(),
legacy: false,
}
}
#[test]
fn validate_accepts_up() {
assert!(args_with_action("up").validate().is_ok());
}
#[test]
fn validate_accepts_down() {
assert!(args_with_action("down").validate().is_ok());
}
#[test]
fn validate_rejects_invalid() {
let err = args_with_action("start").validate().unwrap_err();
assert!(err.to_string().contains("up or down"));
}
}