1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// This is not a normal Rust module! It's included directly into v2.rs,
// possibly after build-time preprocessing.  See v2.rs for an explanation
// of how this works.

#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _IMPL_DESERIALIZE_FOR_Build: () =
    {
        extern crate serde as _serde;
        #[automatically_derived]
        impl _serde::de::Deserialize for Build {
            fn deserialize<__D>(deserializer: &mut __D)
             -> ::std::result::Result<Build, __D::Error> where
             __D: _serde::de::Deserializer {
                #[allow(non_camel_case_types)]
                enum __Field { __field0, __field1, __field2, __field3, }
                impl _serde::de::Deserialize for __Field {
                    #[inline]
                    fn deserialize<__D>(deserializer: &mut __D)
                     -> ::std::result::Result<__Field, __D::Error> where
                     __D: _serde::de::Deserializer {
                        struct __FieldVisitor;
                        impl _serde::de::Visitor for __FieldVisitor {
                            type
                            Value
                            =
                            __Field;
                            fn visit_usize<__E>(&mut self, value: usize)
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    0usize => { Ok(__Field::__field0) }
                                    1usize => { Ok(__Field::__field1) }
                                    2usize => { Ok(__Field::__field2) }
                                    3usize => { Ok(__Field::__field3) }
                                    _ =>
                                    Err(_serde::de::Error::invalid_value("expected a field")),
                                }
                            }
                            fn visit_str<__E>(&mut self, value: &str)
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    "context" => { Ok(__Field::__field0) }
                                    "dockerfile" => { Ok(__Field::__field1) }
                                    "args" => { Ok(__Field::__field2) }
                                    "_phantom" => { Ok(__Field::__field3) }
                                    _ =>
                                    Err(_serde::de::Error::unknown_field(value)),
                                }
                            }
                            fn visit_bytes<__E>(&mut self, value: &[u8])
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    b"context" => { Ok(__Field::__field0) }
                                    b"dockerfile" => { Ok(__Field::__field1) }
                                    b"args" => { Ok(__Field::__field2) }
                                    b"_phantom" => { Ok(__Field::__field3) }
                                    _ => {
                                        let value =
                                            ::std::string::String::from_utf8_lossy(value);
                                        Err(_serde::de::Error::unknown_field(&value))
                                    }
                                }
                            }
                        }
                        deserializer.deserialize_struct_field(__FieldVisitor)
                    }
                }
                struct __Visitor;
                impl _serde::de::Visitor for __Visitor {
                    type
                    Value
                    =
                    Build;
                    #[inline]
                    fn visit_seq<__V>(&mut self, mut visitor: __V)
                     -> ::std::result::Result<Build, __V::Error> where
                     __V: _serde::de::SeqVisitor {
                        let __field0 =
                            match try!(visitor . visit :: < RawOr<Context> > (
                                        )) {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(0usize));
                                }
                            };
                        let __field1 =
                            match try!(visitor . visit :: <
                                       Option<RawOr<String>> > (  )) {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(1usize));
                                }
                            };
                        let __field2 =
                            match {
                                      struct __SerdeDeserializeWithStruct {
                                          value: 

                                          BTreeMap<String, String>,
                                          phantom: ::std::marker::PhantomData<Build>,
                                      }
                                      impl _serde::de::Deserialize for
                                       __SerdeDeserializeWithStruct {
                                          fn deserialize<__D>(__d: &mut __D)
                                           ->
                                               ::std::result::Result<Self,
                                                                     __D::Error>
                                           where
                                           __D: _serde::de::Deserializer {
                                              let value =
                                                  try!(deserialize_map_or_key_value_list
                                                       ( __d ));
                                              Ok(__SerdeDeserializeWithStruct{value:
                                                                                  value,
                                                                              phantom:
                                                                                  ::std::marker::PhantomData,})
                                          }
                                      }
                                      try!(visitor . visit :: <
                                           __SerdeDeserializeWithStruct > (
                                           )).map(|wrap| wrap.value)
                                  } {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(2usize));
                                }
                            };
                        let __field3 = ::std::default::Default::default();
                        try!(visitor . end (  ));
                        Ok(Build{context: __field0,
                                 dockerfile: __field1,
                                 args: __field2,
                                 _phantom: __field3,})
                    }
                    #[inline]
                    fn visit_map<__V>(&mut self, mut visitor: __V)
                     -> ::std::result::Result<Build, __V::Error> where
                     __V: _serde::de::MapVisitor {
                        let mut __field0: Option<RawOr<Context>> = None;
                        let mut __field1: Option<Option<RawOr<String>>> =
                            None;
                        let mut __field2: Option<BTreeMap<String, String>> =
                            None;
                        while let Some(key) =
                                  try!(visitor . visit_key :: < __Field > (
                                       )) {
                            match key {
                                __Field::__field0 => {
                                    if __field0.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("context"));
                                    }
                                    __field0 =
                                        Some(try!(visitor . visit_value :: <
                                                  RawOr<Context> > (  )));
                                }
                                __Field::__field1 => {
                                    if __field1.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("dockerfile"));
                                    }
                                    __field1 =
                                        Some(try!(visitor . visit_value :: <
                                                  Option<RawOr<String>> > (
                                                  )));
                                }
                                __Field::__field2 => {
                                    if __field2.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("args"));
                                    }
                                    __field2 =
                                        Some(({
                                                  struct __SerdeDeserializeWithStruct {
                                                      value: BTreeMap<String,
                                                                      String>,
                                                      phantom: ::std::marker::PhantomData<Build>,
                                                  }
                                                  impl _serde::de::Deserialize
                                                   for
                                                   __SerdeDeserializeWithStruct
                                                   {
                                                      fn deserialize<__D>(__d:
                                                                              &mut __D)
                                                       ->
                                                           ::std::result::Result<Self,
                                                                                 __D::Error>
                                                       where
                                                       __D: _serde::de::Deserializer {
                                                          let value =
                                                              try!(deserialize_map_or_key_value_list
                                                                   ( __d ));
                                                          Ok(__SerdeDeserializeWithStruct{value:
                                                                                              value,
                                                                                          phantom:
                                                                                              ::std::marker::PhantomData,})
                                                      }
                                                  }
                                                  try!(visitor . visit_value
                                                       :: <
                                                       __SerdeDeserializeWithStruct
                                                       > (  )).value
                                              }));
                                }
                                __Field::__field3 => {
                                    try!(visitor . visit_value :: < _serde ::
                                         de :: impls :: IgnoredAny > (  ));
                                }
                            }
                        }
                        try!(visitor . end (  ));
                        let __field0 =
                            match __field0 {
                                Some(__field0) => __field0,
                                None =>
                                try!(visitor . missing_field ( "context" )),
                            };
                        let __field1 =
                            match __field1 {
                                Some(__field1) => __field1,
                                None =>
                                try!(visitor . missing_field ( "dockerfile"
                                     )),
                            };
                        let __field2 =
                            match __field2 {
                                Some(__field2) => __field2,
                                None => ::std::default::Default::default(),
                            };
                        Ok(Build{context: __field0,
                                 dockerfile: __field1,
                                 args: __field2,
                                 _phantom:
                                     ::std::default::Default::default(),})
                    }
                }
                const FIELDS: &'static [&'static str] =
                    &["context", "dockerfile", "args", "_phantom"];
                deserializer.deserialize_struct("Build", FIELDS, __Visitor)
            }
        }
    };
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _IMPL_SERIALIZE_FOR_Build: () =
    {
        extern crate serde as _serde;
        #[automatically_derived]
        impl _serde::ser::Serialize for Build {
            fn serialize<__S>(&self, _serializer: &mut __S)
             -> ::std::result::Result<(), __S::Error> where
             __S: _serde::ser::Serializer {
                let mut state =
                    try!(_serializer . serialize_struct (
                         "Build" ,
                         0 + 1 + if Option::is_none(&self.dockerfile) { 0 } else { 1 } +
    if BTreeMap::is_empty(&self.args) { 0 } else { 1 }
                         ));
                try!(_serializer . serialize_struct_elt (
                     & mut state , "context" , &self.context ));
                if !




                        // We never return an error, so specify `Void` as our error type.







                        // TODO MED: Implement valueless keys.
                        //
                        // args:
                        //   - buildno
                        //   - password
                        Option::is_none(&self.dockerfile) {
                    try!(_serializer . serialize_struct_elt (
                         & mut state , "dockerfile" , &self.dockerfile ))
                }
                if !BTreeMap::is_empty(&self.args) {
                    try!(_serializer . serialize_struct_elt (
                         & mut state , "args" , &self.args ))
                }
                _serializer.serialize_struct_end(state)
            }
        }
    };
/// Information on how to build a Docker image.
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct Build {
    /// The source directory to use for this build.
    pub context: RawOr<Context>,
    /// The name of an alternate `Dockerfile` to use.
    pub dockerfile: Option<RawOr<String>>,
    /// Build arguments.
    pub args: BTreeMap<String, String>,
    /// PRIVATE.  Mark this struct as having unknown fields for future
    /// compatibility.  This prevents direct construction and exhaustive
    /// matching.  This needs to be be public because of
    /// http://stackoverflow.com/q/39277157/12089
    #[doc(hidden)]
    pub _phantom: PhantomData<()>,
}
derive_standard_impls_for! (Build , { context , dockerfile , args , _phantom
                            });
impl Build {
    /// Create a new build from just `Context`.  To override other fields, you
    /// can use struct notation.
    ///
    /// ```
    /// use docker_compose::v2 as dc;
    ///
    /// dc::Build::new(dc::Context::new("app"));
    ///
    /// dc::Build {
    ///   dockerfile: Some(dc::escape("Dockerfile-alt").unwrap()),
    ///   ..dc::Build::new(dc::Context::new("app"))
    /// };
    /// ```
    pub fn new<C: Into<Context>>(ctx: C) -> Self {
        Build{context: value(ctx.into()),
              dockerfile: Default::default(),
              args: Default::default(),
              _phantom: PhantomData,}
    }
}
impl FromStr for Build {
    type
    Err
    =
    Void;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Build::new(Context::new(s)))
    }
}
impl SerializeStringOrStruct for Build {
    fn serialize_string_or_struct<S>(&self, serializer: &mut S)
     -> Result<(), S::Error> where S: Serializer {
        if self.dockerfile.is_none() && self.args.is_empty() {
            self.context.serialize(serializer)
        } else { self.serialize(serializer) }
    }
}
#[test]
fn build_has_a_string_representation() {
    let build: Build = Build::from_str(".").unwrap();
    assert_eq!(build . context , value ( Context :: new ( "." ) ));
    assert_eq!(build . dockerfile , None);
    assert_eq!(build . args , Default :: default (  ));
}
#[test]
fn build_may_be_a_struct() {
    let yaml =
        r#"---
"args":
  "key": "value"
"context": "."
"dockerfile": "Dockerfile"
"#;
    assert_roundtrip!(Build , yaml);
    let build: Build = serde_yaml::from_str(yaml).unwrap();
    assert_eq!(build . context , value ( Context :: new ( "." ) ));
    assert_eq!(build . dockerfile , Some (
               value ( "Dockerfile" . to_owned (  ) ) ));
    assert_eq!(build . args . get ( "key" ) . cloned (  ) , Some (
               "value" . to_owned (  ) ));
}
#[test]
fn build_args_may_be_a_key_value_list() {
    let yaml = "---
context: \".\"
args:
  - \"key=value\"
";
    let build: Build = serde_yaml::from_str(yaml).unwrap();
    assert_eq!(build . args . get ( "key" ) . cloned (  ) , Some (
               "value" . to_owned (  ) ));
}