pub struct CommandConfig { /* private fields */ }
Expand description
Configuration for command execution including arguments and environment variables.
The CommandConfig
struct provides a centralized way to manage command-line
arguments and environment variables that are passed to Ansible commands.
It’s used internally by all the main Ansible wrapper structs.
§Examples
§Basic Usage
use ansible::command_config::CommandConfig;
let mut config = CommandConfig::default();
config
.arg("--verbose")
.arg("--check")
.add_env("ANSIBLE_HOST_KEY_CHECKING", "False");
assert_eq!(config.get_args().len(), 2);
assert!(config.get_envs().contains_key("ANSIBLE_HOST_KEY_CHECKING"));
§Environment Variable Management
use ansible::command_config::CommandConfig;
let mut config = CommandConfig::default();
config
.set_system_envs()
.filter_envs(["HOME", "PATH", "USER"]);
// Only HOME, PATH, and USER environment variables are retained
assert!(config.get_envs().len() <= 3);
Implementations§
Source§impl CommandConfig
impl CommandConfig
Sourcepub fn set_system_envs(&mut self) -> &mut Self
pub fn set_system_envs(&mut self) -> &mut Self
Set environment variables from the current system environment
Sourcepub fn add_env(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
pub fn add_env( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
Add a single environment variable
Sourcepub fn filter_envs<T, S>(&mut self, iter: T) -> &mut Self
pub fn filter_envs<T, S>(&mut self, iter: T) -> &mut Self
Filter environment variables to only include specified keys
Sourcepub fn arg<S: AsRef<OsStr> + Display>(&mut self, arg: S) -> &mut Self
pub fn arg<S: AsRef<OsStr> + Display>(&mut self, arg: S) -> &mut Self
Add a single command argument
Sourcepub fn clear_args(&mut self) -> &mut Self
pub fn clear_args(&mut self) -> &mut Self
Clear all arguments
Sourcepub fn clear_envs(&mut self) -> &mut Self
pub fn clear_envs(&mut self) -> &mut Self
Clear all environment variables
Trait Implementations§
Source§impl Clone for CommandConfig
impl Clone for CommandConfig
Source§fn clone(&self) -> CommandConfig
fn clone(&self) -> CommandConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CommandConfig
impl Debug for CommandConfig
Source§impl Default for CommandConfig
impl Default for CommandConfig
Source§fn default() -> CommandConfig
fn default() -> CommandConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CommandConfig
impl RefUnwindSafe for CommandConfig
impl Send for CommandConfig
impl Sync for CommandConfig
impl Unpin for CommandConfig
impl UnwindSafe for CommandConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more