ftswarm_proto/command/
direct.rs

1use crate::{Deserialized, NameOf, Serialized};
2
3#[derive(Debug)]
4pub enum FtSwarmDirectCommand {
5    Help,
6    Setup,
7    Halt,
8    Whoami,
9    Uptime,
10    StartCli,
11    Custom(String),
12}
13
14impl NameOf for FtSwarmDirectCommand {
15    fn name(&self) -> String {
16        match self {
17            FtSwarmDirectCommand::Help => "help".to_string(),
18            FtSwarmDirectCommand::Setup => "setup".to_string(),
19            FtSwarmDirectCommand::Halt => "halt".to_string(),
20            FtSwarmDirectCommand::Whoami => "whoami".to_string(),
21            FtSwarmDirectCommand::Uptime => "uptime".to_string(),
22            FtSwarmDirectCommand::StartCli => "startCLI".to_string(),
23            FtSwarmDirectCommand::Custom(name) => name.clone(),
24        }
25    }
26}
27
28impl Serialized for FtSwarmDirectCommand {
29    fn serialize(&self) -> String {
30        self.name()
31    }
32}
33
34impl Deserialized for FtSwarmDirectCommand {
35    fn deserialize(value: &String) -> Result<Self, String> where Self: Sized {
36        match value.as_str() {
37            "help" => Ok(FtSwarmDirectCommand::Help),
38            "setup" => Ok(FtSwarmDirectCommand::Setup),
39            "halt" => Ok(FtSwarmDirectCommand::Halt),
40            "whoami" => Ok(FtSwarmDirectCommand::Whoami),
41            "uptime" => Ok(FtSwarmDirectCommand::Uptime),
42            "startCLI" => Ok(FtSwarmDirectCommand::StartCli),
43            _ => Err(format!("Unknown command: {}", value))
44        }
45    }
46}