use std::path::PathBuf;
use righ_dm_rs::RighVersion;
use serde::{Deserialize, Serialize};
use crate::{
runtime::ValorRuntimeEngine,
service::{ValorServiceEntity, ValorServiceId},
};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValorCommonCmdService {
runtime: ValorRuntimeEngine,
version: RighVersion,
command: String,
args: Vec<String>,
}
impl ValorCommonCmdService {
#[allow(unused)]
pub fn command(&self) -> &str {
&self.command
}
#[allow(unused)]
pub fn args(&self) -> &[String] {
&self.args
}
}
impl ValorCommonCmdService {
#[must_use]
pub fn builder() -> ValorCommonCmdServiceBuilder {
ValorCommonCmdServiceBuilder::default()
}
}
#[derive(Debug, Default, Clone)]
pub struct ValorCommonCmdServiceBuilder {
runtime: Option<ValorRuntimeEngine>,
version: Option<RighVersion>,
command: Option<String>,
args: Option<Vec<String>>,
}
impl ValorCommonCmdServiceBuilder {
pub fn runtime(mut self, runtime: ValorRuntimeEngine) -> Self {
self.runtime = Some(runtime);
self
}
pub fn version(mut self, version: RighVersion) -> Self {
self.version = Some(version);
self
}
pub fn command<S: Into<String>>(mut self, command: S) -> Self {
self.command = Some(command.into());
self
}
#[allow(unused)]
pub fn args<A: Into<Vec<String>>>(mut self, args: A) -> Self {
self.args = Some(args.into());
self
}
pub fn build(self) -> anyhow::Result<ValorCommonCmdService> {
let runtime = self.runtime.unwrap_or(ValorRuntimeEngine::Cmd);
let version = self.version.unwrap_or_default();
let command = self.command.unwrap_or_default();
let args = self.args.unwrap_or_default();
Ok(ValorCommonCmdService {
runtime,
version,
command,
args,
})
}
}
impl ValorServiceEntity for ValorCommonCmdService {
fn service_id(&self) -> ValorServiceId {
ValorServiceId::common_cmd()
}
fn runtime(&self) -> ValorRuntimeEngine {
self.runtime.clone()
}
fn version(&self) -> RighVersion {
self.version.clone()
}
fn metadata(&self) -> Option<&[u8]> {
None
}
fn model_path(&self) -> Option<&PathBuf> {
None
}
}