summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsoftprops <d.tangren@gmail.com>2017-06-25 21:29:32 -0400
committersoftprops <d.tangren@gmail.com>2017-06-25 21:29:32 -0400
commit6d784b1e4f7da7bbe837d32f040a37634208e73c (patch)
treea13627f8e5f2c7f805640e90a1a4ff7dfb57e373
parentfe51ec45f98f215a7158bf64b9f10b80ce04e720 (diff)
apply rustfmt
-rw-r--r--.gitignore1
-rw-r--r--examples/containercreate.rs6
-rw-r--r--examples/containerexec.rs6
-rw-r--r--examples/containerinspect.rs5
-rw-r--r--examples/containers.rs3
-rw-r--r--examples/imagebuild.rs3
-rw-r--r--examples/imagedelete.rs5
-rw-r--r--examples/imageinspect.rs5
-rw-r--r--examples/imagepull.rs3
-rw-r--r--examples/info.rs4
-rw-r--r--examples/logs.rs3
-rw-r--r--examples/networkcreate.rs8
-rw-r--r--examples/networkdelete.rs5
-rw-r--r--examples/networkinspect.rs5
-rw-r--r--examples/networks.rs7
-rw-r--r--examples/top.rs6
-rw-r--r--src/builder.rs252
-rw-r--r--src/errors.rs7
-rw-r--r--src/lib.rs346
-rw-r--r--src/tarball.rs15
-rw-r--r--src/transport.rs82
-rw-r--r--src/tty.rs6
22 files changed, 466 insertions, 317 deletions
diff --git a/.gitignore b/.gitignore
index a9d37c5..ee37c06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
+*.bk
target
Cargo.lock
diff --git a/examples/containercreate.rs b/examples/containercreate.rs
index 8d51055..71307b8 100644
--- a/examples/containercreate.rs
+++ b/examples/containercreate.rs
@@ -7,9 +7,9 @@ fn main() {
let docker = Docker::new();
let containers = docker.containers();
if let Some(image) = env::args().nth(1) {
- let info = containers.create(
- &ContainerOptions::builder(image.as_ref()).build()
- ).unwrap();
+ let info = containers
+ .create(&ContainerOptions::builder(image.as_ref()).build())
+ .unwrap();
println!("{:?}", info);
}
}
diff --git a/examples/containerexec.rs b/examples/containerexec.rs
index b41d1ac..e10d245 100644
--- a/examples/containerexec.rs
+++ b/examples/containerexec.rs
@@ -6,7 +6,11 @@ use std::env;
fn main() {
let docker = Docker::new();
let options = ExecContainerOptions::builder()
- .cmd(vec!["bash", "-c", "echo -n \"echo VAR=$VAR on stdout\"; echo -n \"echo VAR=$VAR on stderr\" >&2"])
+ .cmd(vec![
+ "bash",
+ "-c",
+ "echo -n \"echo VAR=$VAR on stdout\"; echo -n \"echo VAR=$VAR on stderr\" >&2",
+ ])
.env(vec!["VAR=value"])
.attach_stdout(true)
.attach_stderr(true)
diff --git a/examples/containerinspect.rs b/examples/containerinspect.rs
index 30f462a..a34b5f3 100644
--- a/examples/containerinspect.rs
+++ b/examples/containerinspect.rs
@@ -6,10 +6,7 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let container = docker.containers()
- .get(&id)
- .inspect()
- .unwrap();
+ let container = docker.containers().get(&id).inspect().unwrap();
println!("{:?}", container);
}
}
diff --git a/examples/containers.rs b/examples/containers.rs
index 9853062..41cce3c 100644
--- a/examples/containers.rs
+++ b/examples/containers.rs
@@ -6,8 +6,7 @@ use shiplift::Docker;
fn main() {
env_logger::init().unwrap();
let docker = Docker::new();
- for c in docker.containers().
- list(&Default::default()).unwrap() {
+ for c in docker.containers().list(&Default::default()).unwrap() {
println!("container -> {:?}", c)
}
}
diff --git a/examples/imagebuild.rs b/examples/imagebuild.rs
index 6de23be..788634e 100644
--- a/examples/imagebuild.rs
+++ b/examples/imagebuild.rs
@@ -6,7 +6,8 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(path) = env::args().nth(1) {
- let image = docker.images()
+ let image = docker
+ .images()
.build(&BuildOptions::builder(path).tag("shiplift_test").build())
.unwrap();
for output in image {
diff --git a/examples/imagedelete.rs b/examples/imagedelete.rs
index 56c35e4..e239865 100644
--- a/examples/imagedelete.rs
+++ b/examples/imagedelete.rs
@@ -6,10 +6,7 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(img) = env::args().nth(1) {
- let image = docker.images()
- .get(&img[..])
- .delete()
- .unwrap();
+ let image = docker.images().get(&img[..]).delete().unwrap();
for status in image {
println!("{:?}", status);
}
diff --git a/examples/imageinspect.rs b/examples/imageinspect.rs
index 388f08e..50144f0 100644
--- a/examples/imageinspect.rs
+++ b/examples/imageinspect.rs
@@ -6,10 +6,7 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let image = docker.images()
- .get(&id)
- .inspect()
- .unwrap();
+ let image = docker.images().get(&id).inspect().unwrap();
println!("{:?}", image);
}
}
diff --git a/examples/imagepull.rs b/examples/imagepull.rs
index 2097f82..d460a41 100644
--- a/examples/imagepull.rs
+++ b/examples/imagepull.rs
@@ -6,7 +6,8 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(img) = env::args().nth(1) {
- let image = docker.images()
+ let image = docker
+ .images()
.pull(&PullOptions::builder().image(img).build())
.unwrap();
for output in image {
diff --git a/examples/info.rs b/examples/info.rs
index c3ad9d6..372b603 100644
--- a/examples/info.rs
+++ b/examples/info.rs
@@ -3,6 +3,6 @@ extern crate shiplift;
use shiplift::Docker;
fn main() {
- let docker = Docker::new();
- println!("info {:?}", docker.info().unwrap());
+ let docker = Docker::new();
+ println!("info {:?}", docker.info().unwrap());
}
diff --git a/examples/logs.rs b/examples/logs.rs
index 60d3c9a..4a1e5a3 100644
--- a/examples/logs.rs
+++ b/examples/logs.rs
@@ -6,7 +6,8 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let mut logs = docker.containers()
+ let mut logs = docker
+ .containers()
.get(&id)
.logs(&Default::default())
.unwrap();
diff --git a/examples/networkcreate.rs b/examples/networkcreate.rs
index b78ddd0..fb664d6 100644
--- a/examples/networkcreate.rs
+++ b/examples/networkcreate.rs
@@ -7,11 +7,11 @@ fn main() {
let docker = Docker::new();
let networks = docker.networks();
if let Some(network_name) = env::args().nth(1) {
- let info = networks.create(
- &NetworkCreateOptions::builder(network_name.as_ref())
+ let info = networks
+ .create(&NetworkCreateOptions::builder(network_name.as_ref())
.driver("bridge")
- .build()
- ).unwrap();
+ .build())
+ .unwrap();
println!("{:?}", info);
}
}
diff --git a/examples/networkdelete.rs b/examples/networkdelete.rs
index e67b798..b824e38 100644
--- a/examples/networkdelete.rs
+++ b/examples/networkdelete.rs
@@ -6,10 +6,7 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let status = docker.networks()
- .get(&id)
- .delete()
- .unwrap();
+ let status = docker.networks().get(&id).delete().unwrap();
println!("{:?}", status);
}
}
diff --git a/examples/networkinspect.rs b/examples/networkinspect.rs
index f290f93..f88b3c2 100644
--- a/examples/networkinspect.rs
+++ b/examples/networkinspect.rs
@@ -6,10 +6,7 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let network = docker.networks()
- .get(&id)
- .inspect()
- .unwrap();
+ let network = docker.networks().get(&id).inspect().unwrap();
println!("{:?}", network);
}
}
diff --git a/examples/networks.rs b/examples/networks.rs
index 18767d1..04b2c24 100644
--- a/examples/networks.rs
+++ b/examples/networks.rs
@@ -6,8 +6,7 @@ use shiplift::Docker;
fn main() {
env_logger::init().unwrap();
let docker = Docker::new();
- for c in docker.networks().
- list(&Default::default()).unwrap() {
- println!("network -> {:?}", c)
- }
+ for c in docker.networks().list(&Default::default()).unwrap() {
+ println!("network -> {:?}", c)
+ }
}
diff --git a/examples/top.rs b/examples/top.rs
index 567107e..79a7f07 100644
--- a/examples/top.rs
+++ b/examples/top.rs
@@ -6,7 +6,11 @@ use std::env;
fn main() {
let docker = Docker::new();
if let Some(id) = env::args().nth(1) {
- let top = docker.containers().get(&id).top(Default::default()).unwrap();
+ let top = docker
+ .containers()
+ .get(&id)
+ .top(Default::default())
+ .unwrap();
println!("{:?}", top);
}
}
diff --git a/src/builder.rs b/src/builder.rs
index bb7adba..042f8da 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -41,28 +41,32 @@ impl PullOptionsBuilder {
}
pub fn image<I>(&mut self, img: I) -> &mut PullOptionsBuilder
- where I: Into<String>
+ where
+ I: Into<String>,
{
self.params.insert("fromImage", img.into());
self
}
pub fn src<S>(&mut self, s: S) -> &mut PullOptionsBuilder
- where S: Into<String>
+ where
+ S: Into<String>,
{
self.params.insert("fromSrc", s.into());
self
}
pub fn repo<R>(&mut self, r: R) -> &mut PullOptionsBuilder
- where R: Into<String>
+ where
+ R: Into<String>,
{
self.params.insert("repo", r.into());
self
}
pub fn tag<T>(&mut self, t: T) -> &mut PullOptionsBuilder
- where T: Into<String>
+ where
+ T: Into<String>,
{
self.params.insert("tag", t.into());
self
@@ -84,7 +88,8 @@ impl BuildOptions {
/// path is expected to be a file path to a directory containing a Dockerfile
/// describing how to build a Docker image
pub fn builder<S>(path: S) -> BuildOptionsBuilder
- where S: Into<String>
+ where
+ S: Into<String>,
{
BuildOptionsBuilder::new(path)
}
@@ -109,14 +114,19 @@ impl BuildOptionsBuilder {
/// path is expected to be a file path to a directory containing a Dockerfile
/// describing how to build a Docker image
pub fn new<S>(path: S) -> BuildOptionsBuilder
- where S: Into<String>
+ where
+ S: Into<String>,
{
- BuildOptionsBuilder { path: path.into(), ..Default::default() }
+ BuildOptionsBuilder {
+ path: path.into(),
+ ..Default::default()
+ }
}
/// set the name of the docker file. defaults to "DockerFile"
pub fn dockerfile<P>(&mut self, path: P) -> &mut BuildOptionsBuilder
- where P: Into<String>
+ where
+ P: Into<String>,
{
self.params.insert("dockerfile", path.into());
self
@@ -124,14 +134,16 @@ impl BuildOptionsBuilder {
/// tag this image with a name after building it
pub fn tag<T>(&mut self, t: T) -> &mut BuildOptionsBuilder
- where T: Into<String>
+ where
+ T: Into<String>,
{
self.params.insert("t", t.into());
self
}
pub fn remote<R>(&mut self, r: R) -> &mut BuildOptionsBuilder
- where R: Into<String>
+ where
+ R: Into<String>,
{
self.params.insert("remote", r.into());
self
@@ -280,24 +292,26 @@ impl ToJson for ContainerOptions {
/// Function to insert a JSON value into a tree where the desired
/// location of the value is given as a path of JSON keys.
-fn insert<'a, I, V>(key_path: &mut Peekable<I>,
- value: &V,
- parent_node: &mut Json)
- where V: ToJson,
- I: Iterator<Item=&'a str>
+fn insert<'a, I, V>(key_path: &mut Peekable<I>, value: &V, parent_node: &mut Json)
+where
+ V: ToJson,
+ I: Iterator<Item = &'a str>,
{
let local_key = key_path.next().unwrap();
if key_path.peek().is_some() {
let node = parent_node
- .as_object_mut().unwrap()
- .entry(local_key.to_string()).or_insert(Json::Object(BTreeMap::new()));
+ .as_object_mut()
+ .unwrap()
+ .entry(local_key.to_string())
+ .or_insert(Json::Object(BTreeMap::new()));
insert(key_path, value, node);
- }
- else {
- parent_node.as_object_mut().unwrap()
- .insert(local_key.to_string(), value.to_json());
+ } else {
+ parent_node.as_object_mut().unwrap().insert(
+ local_key.to_string(),
+ value.to_json(),
+ );
}
}
@@ -312,18 +326,15 @@ impl ContainerOptions {
Ok(json::encode(&self.to_json())?)
}
- pub fn parse_from<'a, K, V>(&self,
- params: &'a HashMap<K, V>,
- body: &mut Json)
- where &'a HashMap<K, V>: IntoIterator,
- K: ToString + Eq + Hash,
- V: ToJson
+ pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut Json)
+ where
+ &'a HashMap<K, V>: IntoIterator,
+ K: ToString + Eq + Hash,
+ V: ToJson,
{
for (k, v) in params.iter() {
let key_string = k.to_string();
- insert(&mut key_string.split(".").peekable(),
- v,
- body)
+ insert(&mut key_string.split(".").peekable(), v, body)
}
}
}
@@ -358,14 +369,20 @@ impl ContainerOptionsBuilder {
pub fn volumes(&mut self, volumes: Vec<&str>) -> &mut ContainerOptionsBuilder {
for v in volumes {
- self.params_list.entry("HostConfig.Binds").or_insert(Vec::new()).push(v.to_owned());
+ self.params_list
+ .entry("HostConfig.Binds")
+ .or_insert(Vec::new())
+ .push(v.to_owned());
}
self
}
pub fn links(&mut self, links: Vec<&str>) -> &mut ContainerOptionsBuilder {
for link in links {
- self.params_list.entry("HostConfig.Links").or_insert(Vec::new()).push(link.to_owned());
+ self.params_list
+ .entry("HostConfig.Links")
+ .or_insert(Vec::new())
+ .push(link.to_owned());
}
self
}
@@ -393,65 +410,91 @@ impl ContainerOptionsBuilder {
pub fn network_mode(&mut self, network: &str) -> &mut ContainerOptionsBuilder {
if !network.is_empty() {
- self.params.insert("HostConfig.NetworkMode", Json::String(network.to_owned()));
+ self.params.insert(
+ "HostConfig.NetworkMode",
+ Json::String(network.to_owned()),
+ );
}
self
}
pub fn env(&mut self, envs: Vec<&str>) -> &mut ContainerOptionsBuilder {
for env in envs {
- self.params_list.entry("Env").or_insert(Vec::new()).push(env.to_owned());
+ self.params_list.entry("Env").or_insert(Vec::new()).push(
+ env.to_owned(),
+ );
}
self
}
pub fn cmd(&mut self, cmds: Vec<&str>) -> &mut ContainerOptionsBuilder {
for cmd in cmds {
- self.params_list.entry("Cmd").or_insert(Vec::new()).push(cmd.to_owned());
+ self.params_list.entry("Cmd").or_insert(Vec::new()).push(
+ cmd.to_owned(),
+ );
}
self
}
pub fn entrypoint(&mut self, entrypoint: &str) -> &mut ContainerOptionsBuilder {
if !entrypoint.is_empty() {
- self.params.insert("Entrypoint", Json::String(entrypoint.to_owned()));
+ self.params.insert(
+ "Entrypoint",
+ Json::String(entrypoint.to_owned()),
+ );
}
self
}
pub fn capabilities(&mut self, capabilities: Vec<&str>) -> &mut ContainerOptionsBuilder {
for c in capabilities {
- self.params_list.entry("HostConfig.CapAdd").or_insert(Vec::new()).push(c.to_owned());
+ self.params_list
+ .entry("HostConfig.CapAdd")
+ .or_insert(Vec::new())
+ .push(c.to_owned());
}
self
}
- pub fn devices(&mut self,
- devices: Vec<HashMap<String, String>>)
- -> &mut ContainerOptionsBuilder {
+ pub fn devices(
+ &mut self,
+ devices: Vec<HashMap<String, String>>,
+ ) -> &mut ContainerOptionsBuilder {
for d in devices {
- self.params_hash.entry("HostConfig.Devices".to_string()).or_insert(Vec::new()).push(d);
+ self.params_hash
+ .entry("HostConfig.Devices".to_string())
+ .or_insert(Vec::new())
+ .push(d);
}
self
}
pub fn log_driver(&mut self, log_driver: &str) -> &mut ContainerOptionsBuilder {
if !log_driver.is_empty() {
- self.params.insert("HostConfig.LogConfig.Type", Json::String(log_driver.to_owned()));
+ self.params.insert(
+ "HostConfig.LogConfig.Type",
+ Json::String(log_driver.to_owned()),
+ );
}
self
}
- pub fn restart_policy(&mut self,
- name: &str,
- maximum_retry_count: u64)
- -> &mut ContainerOptionsBuilder {
+ pub fn restart_policy(
+ &mut self,
+ name: &str,
+ maximum_retry_count: u64,
+ ) -> &mut ContainerOptionsBuilder {
if !name.is_empty() {
- self.params.insert("HostConfig.RestartPolicy.Name", Json::String(name.to_owned()));
+ self.params.insert(
+ "HostConfig.RestartPolicy.Name",
+ Json::String(name.to_owned()),
+ );
}
if name == "on-failure" {
- self.params.insert("HostConfig.RestartPolicy.MaximumRetryCount",
- Json::U64(maximum_retry_count));
+ self.params.insert(
+ "HostConfig.RestartPolicy.MaximumRetryCount",
+ Json::U64(maximum_retry_count),
+ );
}
self
}
@@ -501,14 +544,18 @@ pub struct ExecContainerOptionsBuilder {
impl ExecContainerOptionsBuilder {
pub fn new() -> ExecContainerOptionsBuilder {
- ExecContainerOptionsBuilder { params: HashMap::new(),
- params_bool: HashMap::new() }
+ ExecContainerOptionsBuilder {
+ params: HashMap::new(),
+ params_bool: 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());
+ self.params.entry("Cmd").or_insert(Vec::new()).push(
+ cmd.to_owned(),
+ );
}
self
}
@@ -516,26 +563,30 @@ impl ExecContainerOptionsBuilder {
/// 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.params.entry("Env").or_insert(Vec::new()).push(
+ env.to_owned(),
+ );
}
self
}
-/// Attach to stdout of the exec command
+ /// Attach to stdout of the exec command
pub fn attach_stdout(&mut self, stdout: bool) -> &mut ExecContainerOptionsBuilder {
self.params_bool.insert("AttachStdout", stdout);
self
}
-/// Attach to stderr of the exec command
+ /// Attach to stderr of the exec command
pub fn attach_stderr(&mut self, stderr: bool) -> &mut ExecContainerOptionsBuilder {
self.params_bool.insert("AttachStderr", stderr);
self
}
pub fn build(&self) -> ExecContainerOptions {
- ExecContainerOptions { params: self.params.clone(),
- params_bool: self.params_bool.clone() }
+ ExecContainerOptions {
+ params: self.params.clone(),
+ params_bool: self.params_bool.clone(),
+ }
}
}
@@ -835,7 +886,6 @@ pub struct NetworkListOptions {
}
impl NetworkListOptions {
-
/// serialize options as a string. returns None if no options are defined
pub fn serialize(&self) -> Option<String> {
if self.params.is_empty() {
@@ -850,7 +900,7 @@ impl NetworkListOptions {
pub struct NetworkCreateOptions {
pub name: Option<String>,
params: HashMap<&'static str, String>,
- params_hash: HashMap<String, Vec<HashMap<String, String>>>
+ params_hash: HashMap<String, Vec<HashMap<String, String>>>,
}
impl ToJson for NetworkCreateOptions {
@@ -875,12 +925,11 @@ impl NetworkCreateOptions {
Ok(json::encode(&self.to_json())?)
}
- pub fn parse_from<'a, K, V>(&self,
- params: &'a HashMap<K, V>,
- body: &mut BTreeMap<String, Json>)
- where &'a HashMap<K, V>: IntoIterator,
- K: ToString + Eq + Hash,
- V: ToJson
+ pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut BTreeMap<String, Json>)
+ where
+ &'a HashMap<K, V>: IntoIterator,
+ K: ToString + Eq + Hash,
+ V: ToJson,
{
for (k, v) in params.iter() {
let key = k.to_string();
@@ -889,14 +938,13 @@ impl NetworkCreateOptions {
body.insert(key, value);
}
}
-
}
#[derive(Default)]
pub struct NetworkCreateOptionsBuilder {
name: Option<String>,
params: HashMap<&'static str, String>,
- params_hash: HashMap<String, Vec<HashMap<String, String>>>
+ params_hash: HashMap<String, Vec<HashMap<String, String>>>,
}
impl NetworkCreateOptionsBuilder {
@@ -919,9 +967,15 @@ impl NetworkCreateOptionsBuilder {
self
}
- pub fn label(&mut self, labels: Vec<HashMap<String, String>>) -> &mut NetworkCreateOptionsBuilder {
+ pub fn label(
+ &mut self,
+ labels: Vec<HashMap<String, String>>,
+ ) -> &mut NetworkCreateOptionsBuilder {
for l in labels {
- self.params_hash.entry("Labels".to_string()).or_insert(Vec::new()).push(l)
+ self.params_hash
+ .entry("Labels".to_string())
+ .or_insert(Vec::new())
+ .push(l)
}
self
}
@@ -938,7 +992,7 @@ impl NetworkCreateOptionsBuilder {
/// Interface for connect container to network
pub struct ContainerConnectionOptions {
pub Container: Option<String>,
- params: HashMap<&'static str, String>
+ params: HashMap<&'static str, String>,
}
impl ToJson for ContainerConnectionOptions {
@@ -956,12 +1010,11 @@ impl ContainerConnectionOptions {
Ok(json::encode(&self.to_json())?)
}
- pub fn parse_from<'a, K, V>(&self,
- params: &'a HashMap<K, V>,
- body: &mut BTreeMap<String, Json>)
- where &'a HashMap<K, V>: IntoIterator,
- K: ToString + Eq + Hash,
- V: ToJson
+ pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut BTreeMap<String, Json>)
+ where
+ &'a HashMap<K, V>: IntoIterator,
+ K: ToString + Eq + Hash,
+ V: ToJson,
{
for (k, v) in params.iter() {
let key = k.to_string();
@@ -984,7 +1037,7 @@ impl ContainerConnectionOptions {
self.params.insert("Force", "true".to_owned());
ContainerConnectionOptions {
Container: None,
- params: self.params.clone()
+ params: self.params.clone(),
}
}
}
@@ -998,62 +1051,67 @@ mod tests {
let builder = ContainerOptionsBuilder::new("test_image");
let options = builder.build();
- assert_eq!(r#"{"HostConfig":{},"Image":"test_image"}"#,
- options.serialize().unwrap());
+ assert_eq!(
+ r#"{"HostConfig":{},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
}
#[test]
fn container_options_env() {
- let options =
- ContainerOptionsBuilder::new("test_image")
+ let options = ContainerOptionsBuilder::new("test_image")
.env(vec!["foo", "bar"])
.build();
- assert_eq!(r#"{"Env":["foo","bar"],"HostConfig":{},"Image":"test_image"}"#,
- options.serialize().unwrap());
+ assert_eq!(
+ r#"{"Env":["foo","bar"],"HostConfig":{},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
}
#[test]
fn container_options_host_config() {
- let options =
- ContainerOptionsBuilder::new("test_image")
+ let options = ContainerOptionsBuilder::new("test_image")
.network_mode("host")
.build();
- assert_eq!(r#"{"HostConfig":{"NetworkMode":"host"},"Image":"test_image"}"#,
- options.serialize().unwrap());
+ assert_eq!(
+ r#"{"HostConfig":{"NetworkMode":"host"},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
}
/// Test container options that are nested 3 levels deep.
#[test]
fn container_options_nested() {
- let options =
- ContainerOptionsBuilder::new("test_image")
+ let options = ContainerOptionsBuilder::new("test_image")
.log_driver("fluentd")
.build();
- assert_eq!(r#"{"HostConfig":{"LogConfig":{"Type":"fluentd"}},"Image":"test_image"}"#,
- options.serialize().unwrap());
+ assert_eq!(
+ r#"{"HostConfig":{"LogConfig":{"Type":"fluentd"}},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
}
/// Test the restart policy settings
#[test]
fn container_options_restart_policy() {
- let mut options =
- ContainerOptionsBuilder::new("test_image")
+ let mut options = ContainerOptionsBuilder::new("test_image")
.restart_policy("on-failure", 10)
.build();
assert_eq!(r#"{"HostConfig":{"RestartPolicy":{"MaximumRetryCount":10,"Name":"on-failure"}},"Image":"test_image"}"#,
options.serialize().unwrap());
- options =
- ContainerOptionsBuilder::new("test_image")
+ options = ContainerOptionsBuilder::new("test_image")
.restart_policy("always", 0)
.build();
- assert_eq!(r#"{"HostConfig":{"RestartPolicy":{"Name":"always"}},"Image":"test_image"}"#,
- options.serialize().unwrap());
+ assert_eq!(
+ r#"{"HostConfig":{"RestartPolicy":{"Name":"always"}},"Image":"test_image"}"#,
+ options.serialize().unwrap()
+ );
}
}
diff --git a/src/errors.rs b/src/errors.rs
index 323b609..bb69ea5 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -14,10 +14,7 @@ pub enum Error {
Parse(ParserError),
Http(HttpError),
IO(IoError),
- Fault {
- code: StatusCode,
- message: String,
- },
+ Fault { code: StatusCode, message: String },
}
impl From<ParserError> for Error {
@@ -76,7 +73,7 @@ impl ErrorTrait for Error {
&Error::Parse(ref err) => Some(err),
&Error::Http(ref err) => Some(err),
&Error::IO(ref err) => Some(err),
- _ => None
+ _ => None,
}
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 74234f2..a7be8a0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,12 +36,12 @@ mod tarball;
pub use errors::Error;
pub use builder::{BuildOptions, ContainerOptions, ContainerListOptions, ContainerFilter,
- EventsOptions, ImageFilter, ImageListOptions, LogsOptions,
- PullOptions, RmContainerOptions, ExecContainerOptions,
- NetworkListOptions, NetworkCreateOptions, ContainerConnectionOptions};
+ EventsOptions, ImageFilter, ImageListOptions, LogsOptions, PullOptions,
+ RmContainerOptions, ExecContainerOptions, NetworkListOptions,
+ NetworkCreateOptions, ContainerConnectionOptions};
use hyper::{Client, Url};
use hyper::header::ContentType;
-use hyper::net::{HttpsConnector};
+use hyper::net::HttpsConnector;
use hyper::method::Method;
use hyper_openssl::OpensslClient;
use hyperlocal::UnixSocketConnector;
@@ -62,7 +62,7 @@ use std::path::Path;
use std::time::Duration;
use transport::{tar, Transport};
use hyper::client::Body;
-use url::{form_urlencoded};
+use url::form_urlencoded;
/// Represents the result of all docker operations
pub type Result<T> = std::result::Result<T, Error>;
@@ -81,7 +81,8 @@ pub struct Image<'a, 'b> {
impl<'a, 'b> Image<'a, 'b> {
/// Exports an interface for operations that may be performed against a named image
pub fn new<S>(docker: &'a Docker, name: S) -> Image<'a, 'b>
- where S: Into<Cow<'b, str>>
+ where
+ S: Into<Cow<'b, str>>,
{
Image {
docker: docker,
@@ -97,40 +98,48 @@ impl<'a, 'b> Image<'a, 'b> {
/// Lists the history of the images set of changes
pub fn history(&self) -> Result<Vec<History>> {
- let raw = self.docker.get(&forma