use crate::cli::command::service::install::ServiceInstallArgs;
use crate::cli::command::service::is_running::ServiceIsRunningArgs;
use crate::cli::command::service::logs::ServiceLogsArgs;
use crate::cli::command::service::run::ServiceRunArgs;
use crate::cli::command::service::start::ServiceStartArgs;
use crate::cli::command::service::status::ServiceStatusArgs;
use crate::cli::command::service::stop::ServiceStopArgs;
use crate::cli::command::service::uninstall::ServiceUninstallArgs;
use arbitrary::Arbitrary;
use facet::Facet;
use figue::{self as args};
#[derive(Facet, Arbitrary, PartialEq, Debug)]
pub struct ServiceArgs {
#[facet(args::subcommand)]
pub command: ServiceCommand,
}
#[derive(Facet, Arbitrary, PartialEq, Debug)]
#[repr(u8)]
#[facet(rename_all = "kebab-case")]
pub enum ServiceCommand {
Install(ServiceInstallArgs),
Uninstall(ServiceUninstallArgs),
Start(ServiceStartArgs),
Stop(ServiceStopArgs),
Status(ServiceStatusArgs),
IsRunning(ServiceIsRunningArgs),
Logs(ServiceLogsArgs),
Run(ServiceRunArgs),
}
impl Default for ServiceCommand {
fn default() -> Self {
Self::Status(ServiceStatusArgs)
}
}
impl ServiceArgs {
pub fn invoke(self) -> eyre::Result<()> {
match self.command {
ServiceCommand::Install(args) => args.invoke(),
ServiceCommand::Uninstall(args) => args.invoke(),
ServiceCommand::Start(args) => args.invoke(),
ServiceCommand::Stop(args) => args.invoke(),
ServiceCommand::Status(args) => args.invoke(),
ServiceCommand::IsRunning(args) => args.invoke(),
ServiceCommand::Logs(args) => args.invoke(),
ServiceCommand::Run(args) => args.invoke(),
}
}
}