diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 9f2836558763b..49016564a71df 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -223,7 +223,9 @@ pub struct Args { #[clap(long, global = true)] pub dangerously_disable_package_manager_check: bool, #[clap(flatten, next_help_heading = "Run Arguments")] - pub run_args: Option, + // DO NOT MAKE THIS VISIBLE + // This is explicitly set to None in `run` + run_args: Option, // This should be inside `RunArgs` but clap currently has a bug // around nested flattened optional args: https://github.com/clap-rs/clap/issues/4697 #[clap(flatten)] @@ -459,6 +461,15 @@ impl Args { ); } } + + /// Fetch the run args supplied to the command + pub fn run_args(&self) -> Option<&RunArgs> { + if let Some(Command::Run { run_args, .. }) = &self.command { + Some(run_args) + } else { + self.run_args.as_ref() + } + } } /// Defines the subcommands for CLI. NOTE: If we change the commands in Go, @@ -1041,7 +1052,7 @@ pub async fn run( let mut command = if let Some(command) = mem::take(&mut cli_args.command) { command } else { - let run_args = cli_args.run_args.take().unwrap_or_default(); + let run_args = cli_args.run_args.clone().unwrap_or_default(); let execution_args = cli_args .execution_args // We clone instead of take as take would leave the command base a copy of cli_args diff --git a/crates/turborepo-lib/src/commands/mod.rs b/crates/turborepo-lib/src/commands/mod.rs index 12d8c43958c72..37fc8f52f847f 100644 --- a/crates/turborepo-lib/src/commands/mod.rs +++ b/crates/turborepo-lib/src/commands/mod.rs @@ -88,7 +88,7 @@ impl CommandBase { .dangerously_disable_package_manager_check .then_some(true), ) - .with_daemon(self.args.run_args.as_ref().and_then(|args| args.daemon())) + .with_daemon(self.args.run_args().and_then(|args| args.daemon())) .with_env_mode( self.args .command