diff --git a/doc/podman-pilot.rst b/doc/podman-pilot.rst index d22bad4..4b61301 100644 --- a/doc/podman-pilot.rst +++ b/doc/podman-pilot.rst @@ -116,12 +116,20 @@ can be set for the supported container engine: - -ti After reading of the app configuration information the application -will be called using the configured engine. If no runtime +will be called using the configured engine. If no podman runtime arguments exists, the following defaults will apply: - The instance will be removed after the call - The instance allows for interactive shell sessions +The podman runtime arguments allows to set environment variable +placeholders starting with '%' and followed by the name of the +environment variable. For example %HOME will be replaced to the +value of $HOME of the calling user. If the given placeholder +cannot be translated into an existing environment variable it +will be turned into the variable name, $HOME in the above +example + All caller arguments will be passed to the program call inside of the instance except for arguments that starts with the '@' or '%' sign. Caller arguments of this type are only used for diff --git a/podman-pilot/src/podman.rs b/podman-pilot/src/podman.rs index 9234b1e..c2e0281 100644 --- a/podman-pilot/src/podman.rs +++ b/podman-pilot/src/podman.rs @@ -182,9 +182,28 @@ pub fn create( } // create the container with configured runtime arguments - let has_runtime_args = podman.as_ref().map(|p| !p.is_empty()).unwrap_or_default(); - app.args(podman.iter().flatten().flat_map(|x| x.splitn(2, ' '))); + for arg in podman.iter().flatten().flat_map(|x| x.splitn(2, ' ')) { + let mut arg_value = arg.to_string(); + let var_pattern = Regex::new(r"%([A-Z]+)").unwrap(); + while var_pattern.captures(&arg_value.clone()).is_some() { + for capture in var_pattern.captures_iter(&arg_value.clone()) { + // replace %VAR placeholder(s) with the respective + // environment variable value if possible. + // If not possible replace by the variable name + let var_name = capture.get(1).unwrap().as_str(); + let var_value = env::var(var_name) + .unwrap_or(format!("${}", var_name)); + arg_value = arg_value.replace( + &format!("%{}", var_name), &var_value + ); + } + } + app.arg(arg_value); + }; + // set default runtime arguments if none configured + let has_runtime_args = podman + .as_ref().map(|p| !p.is_empty()).unwrap_or_default(); if !has_runtime_args { app.arg("--tty").arg("--interactive"); }