Skip to content

Commit 00d95fb

Browse files
committed
refactor(hm-dsl-engine): Replace stringly-typed run() mode ("list"/"render") with an internal enum
1 parent 904721f commit 00d95fb

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

crates/hm-dsl-engine/src/ts_engine.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ impl Drop for SymlinkCleanup {
9696
}
9797
}
9898

99+
/// The operation the embedded JS runner should perform.
100+
///
101+
/// Modeled as a closed enum so the dispatch is exhaustive and typo-proof at
102+
/// compile time; the wire string lives in exactly one place (`as_arg`).
103+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104+
enum RunMode {
105+
List,
106+
Render,
107+
}
108+
109+
impl RunMode {
110+
/// The CLI argument passed to the JS runner for this mode.
111+
fn as_arg(self) -> &'static str {
112+
match self {
113+
Self::List => "list",
114+
Self::Render => "render",
115+
}
116+
}
117+
}
118+
99119
#[derive(Debug)]
100120
pub struct SubprocessTsEngine {
101121
runtime: JsRuntime,
@@ -154,7 +174,7 @@ impl SubprocessTsEngine {
154174
}
155175
}
156176

157-
async fn run(&self, project_dir: &Path, mode: &str, slug: Option<&str>) -> Result<String> {
177+
async fn run(&self, project_dir: &Path, mode: RunMode, slug: Option<&str>) -> Result<String> {
158178
let tmp = self.setup_temp()?;
159179
let runner_path = tmp.path().join("runner.mjs");
160180

@@ -218,7 +238,7 @@ impl SubprocessTsEngine {
218238
}
219239
}
220240

221-
cmd.arg(project_dir).arg(mode);
241+
cmd.arg(project_dir).arg(mode.as_arg());
222242

223243
if let Some(s) = slug {
224244
cmd.arg(s);
@@ -247,7 +267,7 @@ impl SubprocessTsEngine {
247267
impl DslEngine for SubprocessTsEngine {
248268
async fn list_pipelines(&self, project_dir: &Path) -> Result<Vec<PipelineMeta>> {
249269
let stdout = self
250-
.run(project_dir, "list", None)
270+
.run(project_dir, RunMode::List, None)
251271
.await
252272
.context("listing pipelines via JS runtime")?;
253273

@@ -257,7 +277,7 @@ impl DslEngine for SubprocessTsEngine {
257277
}
258278

259279
async fn render_pipeline_json(&self, project_dir: &Path, slug: &str) -> Result<String> {
260-
self.run(project_dir, "render", Some(slug))
280+
self.run(project_dir, RunMode::Render, Some(slug))
261281
.await
262282
.context("rendering pipeline via JS runtime")
263283
}

0 commit comments

Comments
 (0)