Skip to content

Commit 3b98c16

Browse files
chore(config): move TURBO_REMOTE_CACHE_READ_ONLY to config
1 parent 37b9729 commit 3b98c16

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

crates/turborepo-lib/src/cli/mod.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ pub struct RunArgs {
898898
#[clap(long, value_parser=NonEmptyStringValueParser::new(), conflicts_with = "profile")]
899899
pub anon_profile: Option<String>,
900900
/// Treat remote cache as read only
901-
#[clap(long, env = "TURBO_REMOTE_CACHE_READ_ONLY", value_name = "BOOL", action = ArgAction::Set, default_value = "false", default_missing_value = "true", num_args = 0..=1)]
902-
pub remote_cache_read_only: bool,
901+
#[clap(long, default_missing_value = "true")]
902+
pub remote_cache_read_only: Option<Option<bool>>,
903903
/// Generate a summary of the turbo run
904904
#[clap(long, env = "TURBO_RUN_SUMMARY", default_missing_value = "true")]
905905
pub summarize: Option<Option<bool>>,
@@ -924,7 +924,7 @@ impl Default for RunArgs {
924924
no_daemon: false,
925925
profile: None,
926926
anon_profile: None,
927-
remote_cache_read_only: false,
927+
remote_cache_read_only: None,
928928
summarize: None,
929929
experimental_space_id: None,
930930
parallel: false,
@@ -954,13 +954,22 @@ impl RunArgs {
954954
}
955955
}
956956

957+
pub fn remote_cache_read_only(&self) -> Option<bool> {
958+
let remote_cache_read_only = self.remote_cache_read_only?;
959+
Some(remote_cache_read_only.unwrap_or(true))
960+
}
961+
957962
pub fn track(&self, telemetry: &CommandEventBuilder) {
958963
// default to true
959964
track_usage!(telemetry, self.no_cache, |val| val);
960965
track_usage!(telemetry, self.daemon, |val| val);
961966
track_usage!(telemetry, self.no_daemon, |val| val);
962967
track_usage!(telemetry, self.parallel, |val| val);
963-
track_usage!(telemetry, self.remote_cache_read_only, |val| val);
968+
track_usage!(
969+
telemetry,
970+
self.remote_cache_read_only().unwrap_or_default(),
971+
|val| val
972+
);
964973

965974
// default to None
966975
track_usage!(telemetry, &self.profile, Option::is_some);

crates/turborepo-lib/src/commands/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ impl CommandBase {
102102
.execution_args()
103103
.and_then(|args| args.remote_only()),
104104
)
105+
.with_remote_cache_read_only(
106+
self.args
107+
.run_args()
108+
.and_then(|args| args.remote_cache_read_only()),
109+
)
105110
.build()
106111
}
107112

crates/turborepo-lib/src/config/env.rs

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TURBO_MAPPING: &[(&str, &str)] = [
3636
("turbo_force", "force"),
3737
("turbo_log_order", "log_order"),
3838
("turbo_remote_only", "remote_only"),
39+
("turbo_remote_cache_read_only", "remote_cache_read_only"),
3940
]
4041
.as_slice();
4142

@@ -82,6 +83,7 @@ impl ResolvedConfigurationOptions for EnvVars {
8283

8384
let force = self.truthy_value("force").flatten();
8485
let remote_only = self.truthy_value("remote_only").flatten();
86+
let remote_cache_read_only = self.truthy_value("remote_cache_read_only").flatten();
8587

8688
// Process timeout
8789
let timeout = self
@@ -165,6 +167,7 @@ impl ResolvedConfigurationOptions for EnvVars {
165167
daemon,
166168
force,
167169
remote_only,
170+
remote_cache_read_only,
168171

169172
// Processed numbers
170173
timeout,
@@ -309,6 +312,7 @@ mod test {
309312
env.insert("turbo_force".into(), "1".into());
310313
env.insert("turbo_log_order".into(), "grouped".into());
311314
env.insert("turbo_remote_only".into(), "1".into());
315+
env.insert("turbo_remote_cache_read_only".into(), "1".into());
312316

313317
let config = EnvVars::new(&env)
314318
.unwrap()
@@ -318,6 +322,7 @@ mod test {
318322
assert!(config.force());
319323
assert_eq!(config.log_order(), LogOrder::Grouped);
320324
assert!(config.remote_only());
325+
assert!(config.remote_cache_read_only());
321326
assert_eq!(turbo_api, config.api_url.unwrap());
322327
assert_eq!(turbo_login, config.login_url.unwrap());
323328
assert_eq!(turbo_team, config.team_slug.unwrap());
@@ -353,6 +358,7 @@ mod test {
353358
env.insert("turbo_force".into(), "".into());
354359
env.insert("turbo_log_order".into(), "".into());
355360
env.insert("turbo_remote_only".into(), "".into());
361+
env.insert("turbo_remote_cache_read_only".into(), "".into());
356362

357363
let config = EnvVars::new(&env)
358364
.unwrap()
@@ -373,6 +379,7 @@ mod test {
373379
assert!(!config.force());
374380
assert_eq!(config.log_order(), LogOrder::Auto);
375381
assert!(!config.remote_only());
382+
assert!(!config.remote_cache_read_only());
376383
}
377384

378385
#[test]

crates/turborepo-lib/src/config/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub struct ConfigurationOptions {
237237
pub(crate) force: Option<bool>,
238238
pub(crate) log_order: Option<LogOrder>,
239239
pub(crate) remote_only: Option<bool>,
240+
pub(crate) remote_cache_read_only: Option<bool>,
240241
}
241242

242243
#[derive(Default)]
@@ -352,6 +353,10 @@ impl ConfigurationOptions {
352353
self.remote_only.unwrap_or_default()
353354
}
354355

356+
pub fn remote_cache_read_only(&self) -> bool {
357+
self.remote_cache_read_only.unwrap_or_default()
358+
}
359+
355360
pub fn root_turbo_json_path(&self, repo_root: &AbsoluteSystemPath) -> AbsoluteSystemPathBuf {
356361
self.root_turbo_json_path
357362
.clone()

crates/turborepo-lib/src/opts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'a> From<OptsInputs<'a>> for CacheOpts {
363363
CacheOpts {
364364
cache_dir: inputs.config.cache_dir().into(),
365365
skip_filesystem: inputs.config.remote_only(),
366-
remote_cache_read_only: inputs.run_args.remote_cache_read_only,
366+
remote_cache_read_only: inputs.config.remote_cache_read_only(),
367367
workers: inputs.run_args.cache_workers,
368368
skip_remote,
369369
remote_cache_opts,

0 commit comments

Comments
 (0)