diff --git a/01_hello/src/bin/true.rs b/01_hello/src/bin/true.rs index f328e4d..44490fa 100644 --- a/01_hello/src/bin/true.rs +++ b/01_hello/src/bin/true.rs @@ -1 +1,3 @@ -fn main() {} +fn main() { + std::process::exit(0); +} diff --git a/02_echor/err b/02_echor/err new file mode 100644 index 0000000..b30201f --- /dev/null +++ b/02_echor/err @@ -0,0 +1,9 @@ + Finished dev [unoptimized + debuginfo] target(s) in 0.00s + Running `target/debug/echor` +error: The following required arguments were not provided: + ... + +USAGE: + echor [FLAGS] ... + +For more information try --help diff --git a/02_echor/out b/02_echor/out new file mode 100644 index 0000000..e69de29 diff --git a/02_echor/src/answer.rs b/02_echor/src/answer.rs new file mode 100644 index 0000000..3bff480 --- /dev/null +++ b/02_echor/src/answer.rs @@ -0,0 +1,26 @@ +use clap::{App, Arg}; + +fn main() { + let matches = App::new("echor") + .version("0.1.0") + .author("Ken Youens-Clark ") + .about("Rust echo") + .arg( + Arg::with_name("text") + .value_name("TEXT") + .help("Input text") + .required(true) + .min_values(1), + ) + .arg( + Arg::with_name("omit_newline") + .short("n") + .help("Do not print newline") + .takes_value(false), + ) + .get_matches(); + + let text = matches.values_of_lossy("text").unwrap(); + let omit_newline = matches.is_present("omit_newline"); + print!("{}{}", text.join(" "), if omit_newline { "" } else { "\n" }); +} diff --git a/02_echor/src/main.rs b/02_echor/src/main.rs index 3bff480..b1d969e 100644 --- a/02_echor/src/main.rs +++ b/02_echor/src/main.rs @@ -1,9 +1,9 @@ use clap::{App, Arg}; - +// use std::env::args; fn main() { let matches = App::new("echor") - .version("0.1.0") - .author("Ken Youens-Clark ") + .version("1.1.0") + .author("Ore Ore ") .about("Rust echo") .arg( Arg::with_name("text") @@ -22,5 +22,6 @@ fn main() { let text = matches.values_of_lossy("text").unwrap(); let omit_newline = matches.is_present("omit_newline"); + print!("{}{}", text.join(" "), if omit_newline { "" } else { "\n" }); }