Skip to content

Commit 3a2427f

Browse files
committed
refactor: simplify command handling by introducing to_synthetic_plan_request method
1 parent 420d3d7 commit 3a2427f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

crates/vite_task/src/session/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@ impl vite_task_plan::PlanRequestParser for PlanRequestParser<'_> {
9898
match self.command_handler.handle_command(command).await? {
9999
HandledCommand::Synthesized(synthetic) => Ok(Some(PlanRequest::Synthetic(synthetic))),
100100
HandledCommand::ViteTaskCommand(cli_command) => match cli_command {
101-
Command::Cache { .. } => Ok(Some(PlanRequest::Synthetic(SyntheticPlanRequest {
102-
program: Arc::from(OsStr::new(command.program.as_str())),
103-
args: Arc::clone(&command.args),
104-
cache_config: UserCacheConfig::disabled(),
105-
envs: Arc::clone(&command.envs),
106-
}))),
101+
Command::Cache { .. } => Ok(Some(PlanRequest::Synthetic(
102+
command.to_synthetic_plan_request(UserCacheConfig::disabled()),
103+
))),
107104
Command::Run(run_command) => Ok(Some(run_command.into_plan_request(&command.cwd)?)),
108105
},
109106
HandledCommand::Verbatim => Ok(None),

crates/vite_task_plan/src/plan_request.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ pub struct ScriptCommand {
1818
pub cwd: Arc<AbsolutePath>,
1919
}
2020

21+
impl ScriptCommand {
22+
/// Convert this `ScriptCommand` to a `PlanRequest::Synthetic` with the given `cache_config`.
23+
pub fn to_synthetic_plan_request(&self, cache_config: UserCacheConfig) -> SyntheticPlanRequest {
24+
SyntheticPlanRequest {
25+
program: Arc::from(OsStr::new(&self.program)),
26+
args: self.args.clone(),
27+
cache_config,
28+
envs: self.envs.clone(),
29+
}
30+
}
31+
}
32+
2133
#[derive(Debug)]
2234
pub struct PlanOptions {
2335
pub extra_args: Arc<[Str]>,

0 commit comments

Comments
 (0)