Skip to main content

nanite_docker/instruction/
shell.rs

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