//! Interfaces for building various structures
use rustc_serialize::json::{self, Json, ToJson};
use self::super::Result;
use std::cmp::Eq;
use std::collections::{BTreeMap, HashMap};
use std::iter::Peekable;
use std::hash::Hash;
use std::iter::IntoIterator;
use url::form_urlencoded;
#[derive(Default)]
pub struct PullOptions {
params: HashMap<&'static str, String>,
}
impl PullOptions {
/// return a new instance of a builder for options
pub fn builder() -> PullOptionsBuilder {
PullOptionsBuilder::new()
}
/// serialize options as a string. returns None if no options are defined
pub fn serialize(&self) -> Option<String> {
if self.params.is_empty() {
None
} else {
Some(form_urlencoded::serialize(&self.params))
}
}
}
#[derive(Default)]
pub struct PullOptionsBuilder {
params: HashMap<&'static str, String>,
}
impl PullOptionsBuilder {
pub fn new() -> PullOptionsBuilder {
PullOptionsBuilder { ..Default::default() }
}
pub fn image<I>(&mut self, img: I) -> &mut PullOptionsBuilder
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>
{
self.params.insert("fromSrc", s.into());
self
}
pub fn repo<R>(&mut self, r: R) -> &mut PullOptionsBuilder
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>
{
self.params.insert("tag", t.into());
self
}
pub fn build(&self) -> PullOptions {
PullOptions { params: self.params.clone() }
}
}
#[derive(Default)]
pub struct BuildOptions {
pub path: String,
params: HashMap<&'static str, String>,
}
impl BuildOptions {
/// return a new instance of a builder for options
/// 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>
{
BuildOptionsBuilder::new(path)
}
/// serialize options as a string. returns None if no options are defined
pub fn serialize(&self) -> Option<String> {
if self.params.is_empty() {
None
} else {
Some(form_urlencoded::serialize(&self.params))
}
}
}
#[derive(Default)]
pub struct BuildOptionsBuilder {
path: String,
params: HashMap<&'static str, String>,
}
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>
{
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>
{
self.params.insert("dockerfile", path.into());
self
}
/// tag this image with a name after building it
pub fn tag<T>(&mut self, t: T) -> &mut BuildOptionsBuilder
where T: Into<String>
{
self.params.insert("t", t.into());
self
}
pub fn