Skip to content

Commit 5052e01

Browse files
committed
Allow parsing execution_completion_behaviour from environment variable.
1 parent dbef3ff commit 5052e01

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

nativelink-config/src/cas_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::serde_utils::{
2424
convert_data_size_with_shellexpand, convert_duration_with_shellexpand,
2525
convert_numeric_with_shellexpand, convert_optional_numeric_with_shellexpand,
2626
convert_optional_string_with_shellexpand, convert_string_with_shellexpand,
27-
convert_vec_string_with_shellexpand,
27+
convert_vec_string_with_shellexpand, convert_enum_with_shellexpand,
2828
};
2929
use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreRefName, StoreSpec};
3030

@@ -854,7 +854,7 @@ pub struct LocalWorkerConfig {
854854
/// Default: None (directory cache disabled)
855855
pub directory_cache: Option<DirectoryCacheConfig>,
856856

857-
#[serde(default)]
857+
#[serde(deserialize_with = "convert_enum_with_shellexpand")]
858858
pub execution_completion_behaviour: ExecutionCompletionBehaviour,
859859
}
860860

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
@@ -479,3 +479,17 @@ where
479479

480480
deserializer.deserialize_any(DurationVisitor::<T>(PhantomData))
481481
}
482+
483+
pub fn convert_enum_with_shellexpand<'de, D, T>(deserializer: D) -> Result<T, D::Error>
484+
where
485+
D: Deserializer<'de>,
486+
T: DeserializeOwned,
487+
{
488+
let s = String::deserialize(deserializer)?;
489+
let expanded = shellexpand::env(&s)
490+
.map_err(de::Error::custom)?;
491+
492+
let quoted = format!("\"{}\"", expanded);
493+
serde_json5::from_str(&quoted)
494+
.map_err(de::Error::custom)
495+
}

0 commit comments

Comments
 (0)