use crate::{DispatcherError, LogLine, ProcInfo};
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Cli;
#[derive(Subcommand, Debug, Serialize, Deserialize)]
pub enum ExecCommand {
Run {
args: Vec<String>,
},
Runat {
at: String,
args: Vec<String>,
},
Start {
service: String,
},
Up {
group: String,
},
}
#[derive(Subcommand, Debug, Serialize, Deserialize)]
pub enum QueryCommand {
Ps,
Logs,
Exit,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum Message {
Connect,
ExecCommand(ExecCommand),
QueryCommand(QueryCommand),
PsInfo(ProcInfo),
LogLine(LogLine),
Ok,
Err(String),
}
impl From<ExecCommand> for Message {
fn from(cmd: ExecCommand) -> Self {
Message::ExecCommand(cmd)
}
}
impl From<QueryCommand> for Message {
fn from(cmd: QueryCommand) -> Self {
Message::QueryCommand(cmd)
}
}
impl From<Result<(), DispatcherError>> for Message {
fn from(res: Result<(), DispatcherError>) -> Self {
if let Err(e) = res {
Message::Err(format!("{e}"))
} else {
Message::Ok
}
}
}