Support ENV variables in CD names
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
use tool_helper::{format_if_error, path_with_env_from};
|
||||
use tool_helper::{format_if_error, path_with_env_from, string_with_env_from};
|
||||
use crate::config_reader::Directory;
|
||||
|
||||
use super::{CommonProperties, Configuration, Error, File, FileKind, LZ4State};
|
||||
@@ -132,7 +132,7 @@ fn read_common_properties(xml: &roxmltree::Node, is_hidden: bool, force_lz4_stat
|
||||
};
|
||||
|
||||
Ok(CommonProperties{
|
||||
name: String::from(xml.attribute(attribute_names::NAME).unwrap_or_default()),
|
||||
name: string_with_env_from(xml.attribute(attribute_names::NAME).unwrap_or_default()),
|
||||
is_hidden: is_hidden | parse_boolean_attribute(&xml, attribute_names::HIDDEN)?,
|
||||
lz4_state,
|
||||
padded_size: read_padded_size(&xml)?
|
||||
|
@@ -38,6 +38,8 @@ macro_rules! format_if_error_drop_cause {
|
||||
};
|
||||
}
|
||||
|
||||
const DEFAULT_ENV_EXPAND_OPTIONS : ExpandOptions = ExpandOptions{expansion_type: Some(ExpansionType::All), default_to_empty: false};
|
||||
|
||||
pub struct Error {
|
||||
pub exit_code: i32,
|
||||
pub text: String,
|
||||
@@ -162,8 +164,12 @@ pub fn callback_if_any_error<F: Fn(String) -> String, T, E: std::string::ToStrin
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string_with_env_from(str: &str) -> String {
|
||||
String::from(envmnt::expand(str, Some(DEFAULT_ENV_EXPAND_OPTIONS)))
|
||||
}
|
||||
|
||||
pub fn path_with_env_from(path: &str) -> PathBuf {
|
||||
PathBuf::from(envmnt::expand(path, Some(ExpandOptions{expansion_type: Some(ExpansionType::All), default_to_empty: false})))
|
||||
PathBuf::from(envmnt::expand(path, Some(DEFAULT_ENV_EXPAND_OPTIONS)))
|
||||
}
|
||||
|
||||
pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
|
||||
|
Reference in New Issue
Block a user