Skip to content

Commit

Permalink
fix(daemon): use correct arg group for deciding daemon config (#9088)
Browse files Browse the repository at this point in the history
### Description

#8728 accidentally disconnected
the `--no-daemon` and `--daemon` flags. The config was populated using
`args.run_args` which is explicitly set to `None` for all `run` commands
[here](https://github.com/vercel/turborepo/blob/main/crates/turborepo-lib/src/cli/mod.rs#L1044).

This resulted in the config never getting the flag values.

### Testing Instructions

Before
```
[0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --no-daemon -vv 2>&1 | rg turbod
2024-08-30T16:05:12.441-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since we appear to be in a non-interactive context
[0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --daemon -vv 2>&1 | rg turbod 
2024-08-30T16:05:23.639-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since we appear to be in a non-interactive context
```

After
```
[1 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --no-daemon -vv 2>&1 | rg turbod 
2024-08-30T15:59:27.083-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since --no-daemon was passed
[0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --daemon -vv 2>&1 | rg turbod 
2024-08-30T15:59:34.093-0400 [DEBUG] turborepo_lib::daemon::connector: looking for pid in lockfile: AbsoluteSystemPathBuf("/var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/turbod/5e203d2ff6cb65bf/turbod.pid")
```
  • Loading branch information
chris-olszewski authored Aug 30, 2024
1 parent 2f8ff7b commit 3f9c869
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RunArgs>,
// DO NOT MAKE THIS VISIBLE
// This is explicitly set to None in `run`
run_args: Option<RunArgs>,
// 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)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f9c869

Please sign in to comment.