Skip to content

Commit 45be08c

Browse files
committed
Allow parsing execution_completion_behaviour from environment variable.
1 parent abc93ac commit 45be08c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

nativelink-config/src/cas_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::serde_utils::{
2222
convert_data_size_with_shellexpand, convert_duration_with_shellexpand,
2323
convert_numeric_with_shellexpand, convert_optional_numeric_with_shellexpand,
2424
convert_optional_string_with_shellexpand, convert_string_with_shellexpand,
25-
convert_vec_string_with_shellexpand,
25+
convert_vec_string_with_shellexpand, convert_enum_with_shellexpand,
2626
};
2727
use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreRefName, StoreSpec};
2828

@@ -804,7 +804,7 @@ pub struct LocalWorkerConfig {
804804
/// Default: None (directory cache disabled)
805805
pub directory_cache: Option<DirectoryCacheConfig>,
806806

807-
#[serde(default)]
807+
#[serde(deserialize_with = "convert_enum_with_shellexpand")]
808808
pub execution_completion_behaviour: ExecutionCompletionBehaviour,
809809
}
810810

nativelink-config/src/serde_utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::fmt;
1818

1919
use byte_unit::Byte;
2020
use humantime::parse_duration;
21-
use serde::de::Visitor;
21+
use serde::de::{DeserializeOwned, Visitor};
2222
use serde::{Deserialize, Deserializer, de};
2323

2424
/// Helper for serde macro so you can use shellexpand variables in the json configuration
@@ -362,3 +362,17 @@ where
362362

363363
deserializer.deserialize_any(DurationVisitor::<T>(PhantomData))
364364
}
365+
366+
pub fn convert_enum_with_shellexpand<'de, D, T>(deserializer: D) -> Result<T, D::Error>
367+
where
368+
D: Deserializer<'de>,
369+
T: DeserializeOwned,
370+
{
371+
let s = String::deserialize(deserializer)?;
372+
let expanded = shellexpand::env(&s)
373+
.map_err(de::Error::custom)?;
374+
375+
let quoted = format!("\"{}\"", expanded);
376+
serde_json5::from_str(&quoted)
377+
.map_err(de::Error::custom)
378+
}

0 commit comments

Comments
 (0)