diff options
author | Joxit <joxit972@gmail.com> | 2017-01-31 21:36:45 +0100 |
---|---|---|
committer | Joxit <joxit972@gmail.com> | 2017-01-31 21:36:45 +0100 |
commit | 4727f283e6fc73f4a3e2498dc4c89f6e7d17df93 (patch) | |
tree | fc4b65102b494b3641579e2f7307e588e8ba03b0 | |
parent | 0b38072da28199057f58f1c4dd1c05fb447801c2 (diff) |
[ExecContainer] Add env option for exec command and update example
-rw-r--r-- | examples/containerexec.rs | 14 | ||||
-rw-r--r-- | src/builder.rs | 9 |
2 files changed, 18 insertions, 5 deletions
diff --git a/examples/containerexec.rs b/examples/containerexec.rs index 25475da..fe542f2 100644 --- a/examples/containerexec.rs +++ b/examples/containerexec.rs @@ -5,12 +5,16 @@ use std::env; fn main() { let docker = Docker::new(); - let options = ExecContainerOptions::builder().cmd(vec!["ls"]).build(); + let options = ExecContainerOptions::builder() + .cmd(vec!["ls"]) + .env(vec!["VAR=value"]) + .build(); if let Some(id) = env::args().nth(1) { - let container = docker.containers() + match docker.containers() .get(&id) - .exec(&options) - .unwrap(); - println!("{:?}", container); + .exec(&options) { + Ok(res) => println!("Success: {:?}", res), + Err(err) => println!("An error occured: {:?}", err), + } } } diff --git a/src/builder.rs b/src/builder.rs index 4b80e57..c13dca6 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -458,6 +458,7 @@ impl ExecContainerOptionsBuilder { ExecContainerOptionsBuilder { params: HashMap::new() } } + /// Command to run, as an array of strings pub fn cmd(&mut self, cmds: Vec<&str>) -> &mut ExecContainerOptionsBuilder { for cmd in cmds { self.params.entry("Cmd").or_insert(Vec::new()).push(cmd.to_owned()); @@ -465,6 +466,14 @@ impl ExecContainerOptionsBuilder { self } + /// A list of environment variables in the form "VAR=value" + pub fn env(&mut self, envs: Vec<&str>) -> &mut ExecContainerOptionsBuilder { + for env in envs { + self.params.entry("Env").or_insert(Vec::new()).push(env.to_owned()); + } + self + } + pub fn build(&self) -> ExecContainerOptions { ExecContainerOptions { params: self.params.clone() } } |