Skip to content

Commit

Permalink
Merge pull request #1031 from imageworks/hyphens-in-env-var-names
Browse files Browse the repository at this point in the history
Change any hyphens in SPK_OPT_* env var names
  • Loading branch information
jrray authored Jun 3, 2024
2 parents 080f5de + 46dde0d commit 00531b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/spk-schema/crates/foundation/src/name/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub use error::{Error, Result};
use miette::Diagnostic;
use thiserror::Error;

use crate::spec_ops::EnvName;

#[cfg(test)]
#[path = "./name_test.rs"]
mod name_test;
Expand Down Expand Up @@ -264,6 +266,12 @@ impl OptNameBuf {
}
}

impl EnvName for OptNameBuf {
fn env_name(&self) -> String {
self.0.replace('-', "_")
}
}

/// Ensure that the provided string is a valid option name.
///
/// This is for checking option names with or without any leading
Expand Down
3 changes: 2 additions & 1 deletion crates/spk-schema/crates/foundation/src/option_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

use crate::name::{OptName, OptNameBuf, PkgName};
use crate::spec_ops::EnvName;

mod error;
mod format;
Expand Down Expand Up @@ -186,7 +187,7 @@ impl OptionMap {
pub fn to_environment(&self) -> HashMap<String, String> {
let mut out = HashMap::default();
for (name, value) in self.iter() {
let var_name = format!("SPK_OPT_{name}");
let var_name = format!("SPK_OPT_{}", name.env_name());
out.insert(var_name, value.into());
}
out
Expand Down

0 comments on commit 00531b8

Please sign in to comment.