diff --git a/Cargo.toml b/Cargo.toml index 6d962cf..7181200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "3.1.6", features = ["derive"] } +regex = { version = "*" } diff --git a/src/main.rs b/src/main.rs index e7a11a9..ed77b21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,16 @@ -fn main() { - println!("Hello, world!"); +use clap::Parser; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +struct Arguments { + #[clap(short, long, default_value = ".carman")] + conf_file: String, +} + +fn main() { + let args = Arguments::parse(); + + println!("Hello, world!"); + println!("{:?}", args); } diff --git a/tests/integration.rs b/tests/integration.rs index 659306e..72a569b 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,8 +1,9 @@ // filename: tests/integration.rs - mod integration { + use regex::Regex; use std::process::Command; + use std::process::Output; static WITHOUT_ARGS_OUTPUT: &'static str = " USAGE: carman [FLAGS] [OPTIONS] @@ -10,12 +11,24 @@ mod integration { "; #[test] - fn calling_carman_without_args() { - let output = Command::new("./target/debug/carman") + fn calling_carman_without_args_returns_result() { + let output = Command::new("./target/debug/carman") .output() .expect("failed to execute process"); - - assert_eq!(String::from_utf8_lossy(&output.stderr), WITHOUT_ARGS_OUTPUT); + let re = Regex::new(r"^Hello").unwrap(); + assert!(re.is_match(&String::from_utf8_lossy(&output.stdout))); + } + + #[test] + fn calling_carman_with_help_returns_usage() { + let output = Command::new("./target/debug/carman") + .arg("--help") + .output() + .expect("failed to execute process"); + let re = Regex::new(r"^carman").unwrap(); + assert!(re.is_match(&String::from_utf8_lossy(&output.stdout))); + let re = Regex::new(r"--help").unwrap(); + assert!(re.is_match(&String::from_utf8_lossy(&output.stdout))); } }