Skip to main content

muster/domain/value/
command_line.rs

1use nutype::nutype;
2
3/// The shell command used to launch a process: trimmed and non-empty.
4#[nutype(
5    sanitize(trim),
6    validate(not_empty),
7    derive(
8        Debug,
9        Clone,
10        PartialEq,
11        Eq,
12        Hash,
13        AsRef,
14        Display,
15        Serialize,
16        Deserialize
17    )
18)]
19pub struct CommandLine(String);
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn keeps_inner_spacing_but_trims_edges() {
27        let cmd = CommandLine::try_new("  npm run dev  ").unwrap();
28        assert_eq!(cmd.as_ref(), "npm run dev");
29    }
30
31    #[test]
32    fn rejects_blank() {
33        assert!(CommandLine::try_new("   ").is_err());
34    }
35}