Skip to main content

nanite_docker/instruction/
cmd.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3use core::fmt::{Display, Formatter};
4
5/// Represents a `CMD` instruction
6///
7/// ```rust
8/// use nanite_docker::{Cmd};
9///
10/// let cmd = Cmd {
11///     argv: vec![
12///         "arg1".to_string(),
13///         "arg2".to_string(),
14///     ],
15/// };
16/// let cmd_built = format!("{cmd}");
17/// assert_eq!(cmd_built, r#"CMD ["arg1", "arg2"]"#);
18/// ```
19#[derive(Clone, Debug)]
20pub struct Cmd {
21    pub argv: Vec<String>,
22}
23impl Display for Cmd {
24    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
25        write!(f, "CMD [")?;
26
27        for (i, arg) in self.argv.iter().enumerate() {
28            if i != 0 {
29                write!(f, ", ")?;
30            }
31            write!(f, r#""{arg}""#)?;
32        }
33
34        write!(f, "]")?;
35
36        Ok(())
37    }
38}