Skip to content

Commit 29c5bf2

Browse files
committed
add TaskCLIArgs::custom_subcommand
1 parent 94eeda7 commit 29c5bf2

File tree

1 file changed

+23
-3
lines changed
  • crates/vite_task/src/cli

1 file changed

+23
-3
lines changed

crates/vite_task/src/cli/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@ use vite_str::Str;
66
use vite_task_graph::{TaskSpecifier, query::TaskQueryKind};
77
use vite_task_plan::plan_request::{PlanOptions, PlanRequest, QueryPlanRequest};
88

9-
/// Represents the CLI arguments handled by vite-task, including both built-in and custom subcommands.
9+
/// Represents the CLI arguments handled by vite-task, including both built-in (like run) and custom subcommands (like lint).
1010
#[derive(Debug)]
1111
pub struct TaskCLIArgs<CustomSubcommand: Subcommand> {
1212
pub(crate) original: Arc<[Str]>,
1313
pub(crate) parsed: ParsedTaskCLIArgs<CustomSubcommand>,
1414
}
1515

16+
impl<CustomSubcommand: Subcommand> TaskCLIArgs<CustomSubcommand> {
17+
/// Inspect the custom subcommand (like lint/install). Returns `None` if it's built-in subcommand
18+
/// The caller should not use this method to actually handle the custom subcommand. Instead, it should
19+
/// private TaskSynthesizer to Session so that vite-task can handle custom subcommands consistenly from
20+
/// both direct CLI invocations and invocations in task scripts.
21+
///
22+
/// This method is provided only to make it possible for the caller to behave differently BEFORE and AFTER the session.
23+
/// For example, vite+ needs this method to skip auto-install when the custom subcommand is alreay `install`.
24+
pub fn custom_subcommand(&self) -> Option<&CustomSubcommand> {
25+
match &self.parsed {
26+
ParsedTaskCLIArgs::BuiltIn(_) => None,
27+
ParsedTaskCLIArgs::Custom(custom) => Some(custom),
28+
}
29+
}
30+
}
31+
32+
/// Represents the overall CLI arguments, containing three kinds of subcommands:
33+
/// 1. Built-in subcommands handled by vite-task (like run)
34+
/// 2. Custom subcommands handled by vite-task with the help of TaskSyntheizer (like lint)
35+
/// 3. Custom subcommands not handled by vite-task (like vite+ commands without cache)
1636
pub enum CLIArgs<CustomSubcommand: Subcommand, NonTaskSubcommand: Subcommand> {
17-
/// vite-task's own built-in subcommands
37+
/// Subcommands handled by vite task, including built-in (like run) and custom (like lint)
1838
Task(TaskCLIArgs<CustomSubcommand>),
19-
/// custom subcommands provided by vite+
39+
/// Custom subcommands not handled by vite task (like vite+ commands without cache)
2040
NonTask(NonTaskSubcommand),
2141
}
2242

0 commit comments

Comments
 (0)