1use clap::Parser;
2
3const TITLE: &str = r#"
4 ____ _ __ __ _ _
5| _ \ _ _ ___| |_ _ \ \ / /_ _| |_ ___| |__
6| |_) | | | / __| __| | | \ \ /\ / / _` | __/ __| '_ \
7| _ <| |_| \__ \ |_| |_| |\ V V / (_| | || (__| | | |
8|_| \_\\__,_|___/\__|\__, | \_/\_/ \__,_|\__\___|_| |_|
9 |___/
10"#;
11
12pub fn title() {
13 println!("{}", TITLE);
14}
15
16#[derive(Parser, Debug)]
17#[clap(
18 version,
19 author = clap::crate_authors!("\n"),
20 about,
21 rename_all_env = "screaming-snake",
22 help_template = "\
23{before-help}{name} {version}
24{author-with-newline}{about-with-newline}
25{usage-heading}
26 {usage}
27
28{all-args}{after-help}
29",
30)]
31pub struct Args {
32 #[arg(short = 'd', long = "dir", default_value = ".")]
33 pub dir: Option<String>,
34
35 #[arg(short = 'c', long = "cmd")]
36 pub command: Option<Vec<String>>,
37
38 #[arg(short = 'i', long)]
39 pub ignore: Option<Vec<String>>,
40
41 #[arg(long)]
42 pub bin_path: Option<String>,
43
44 #[arg(long, allow_hyphen_values = true)]
45 pub bin_arg: Option<Vec<String>>,
46
47 #[arg(long = "cfg", default_value_t = String::from("rustywatch.yaml"))]
48 pub config: String,
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_args_creation() {
57 let args = Args {
58 dir: Some(String::from("/test/dir")),
59 command: Some(vec![String::from("test_command")]),
60 ignore: Some(vec![String::from(".git")]),
61 bin_path: None,
62 bin_arg: Some(vec![String::from("server")]),
63 config: String::from("rustywatch.yaml"),
64 };
65
66 assert_eq!(args.dir.unwrap(), "/test/dir");
67 assert_eq!(args.command.unwrap()[0], "test_command");
68 assert_eq!(args.ignore.unwrap()[0], ".git");
69
70 match args.bin_path {
71 Some(cmd_bin) => assert_eq!(cmd_bin, ""),
72 None => assert_eq!(args.bin_path.is_none(), true),
73 };
74
75 match args.bin_arg {
76 Some(arg) => {
77 for a in arg {
78 assert_eq!(a.as_str(), "server")
79 }
80 }
81 None => {}
82 }
83
84 assert_eq!(args.config, String::from("rustywatch.yaml"))
85 }
86}