Skip to main content

celestial_pointing/commands/
lose.rs

1use super::{Command, CommandOutput};
2use crate::error::Result;
3use crate::session::Session;
4
5pub struct Lose;
6
7impl Command for Lose {
8    fn name(&self) -> &str {
9        "LOSE"
10    }
11    fn description(&self) -> &str {
12        "Remove term(s) from model"
13    }
14
15    fn execute(&self, session: &mut Session, args: &[&str]) -> Result<CommandOutput> {
16        if args.is_empty() {
17            return Err(crate::error::Error::Parse(
18                "LOSE requires term name(s) or ALL".into(),
19            ));
20        }
21        if args.len() == 1 && args[0].eq_ignore_ascii_case("ALL") {
22            session.model.remove_all();
23            return Ok(CommandOutput::Text("All terms removed".into()));
24        }
25        for name in args {
26            session.model.remove_term(&name.to_uppercase());
27        }
28        Ok(CommandOutput::Text(format!(
29            "Removed: {}",
30            args.join(", ").to_uppercase()
31        )))
32    }
33}