Skip to main content

celestial_pointing/commands/
parallel.rs

1use super::{Command, CommandOutput};
2use crate::error::{Error, Result};
3use crate::session::Session;
4
5pub struct Parallel;
6pub struct Chain;
7
8impl Command for Parallel {
9    fn name(&self) -> &str {
10        "PARALLEL"
11    }
12    fn description(&self) -> &str {
13        "Apply terms in parallel"
14    }
15
16    fn execute(&self, session: &mut Session, args: &[&str]) -> Result<CommandOutput> {
17        if args.is_empty() {
18            return Err(Error::Parse("PARALLEL requires term names or ALL".into()));
19        }
20        if args[0].eq_ignore_ascii_case("ALL") {
21            session.model.set_all_parallel();
22            return Ok(CommandOutput::Text(format!(
23                "All {} terms set to parallel",
24                session.model.term_count()
25            )));
26        }
27        let mut set = Vec::new();
28        for name in args {
29            let upper = name.to_uppercase();
30            if session.model.set_parallel(&upper) {
31                set.push(upper);
32            } else {
33                return Err(Error::Parse(format!("term {} not in model", name)));
34            }
35        }
36        Ok(CommandOutput::Text(format!("Parallel: {}", set.join(" "))))
37    }
38}
39
40impl Command for Chain {
41    fn name(&self) -> &str {
42        "CHAIN"
43    }
44    fn description(&self) -> &str {
45        "Apply terms sequentially (chained)"
46    }
47
48    fn execute(&self, session: &mut Session, args: &[&str]) -> Result<CommandOutput> {
49        if args.is_empty() {
50            return Err(Error::Parse("CHAIN requires term names or ALL".into()));
51        }
52        if args[0].eq_ignore_ascii_case("ALL") {
53            session.model.set_all_chained();
54            return Ok(CommandOutput::Text(format!(
55                "All {} terms set to chained",
56                session.model.term_count()
57            )));
58        }
59        let mut set = Vec::new();
60        for name in args {
61            let upper = name.to_uppercase();
62            if session.model.set_chained(&upper) {
63                set.push(upper);
64            } else {
65                return Err(Error::Parse(format!("term {} not in model", name)));
66            }
67        }
68        Ok(CommandOutput::Text(format!("Chained: {}", set.join(" "))))
69    }
70}