flagon-io/hello

public

Greets people from the command line. The sample repository for g1t.

Commit

Merge #64: Add a --bye flag

g1t merge queuecommitted Parentsd9bb608d4eb1c4Browse files
2 files+15−10/2 viewed
+11−0
3838 pub quiet: bool,
3939 /// Whether to end the greeting with three exclamation marks (`--loud`).
4040 pub loud: bool,
41+ /// Whether to print a goodbye after the greeting (`--bye`).
42+ pub bye: bool,
4143 }
4244
4345 impl Default for Options {
5052 lang: Lang::En,
5153 quiet: false,
5254 loud: false,
55+ bye: false,
5356 }
5457 }
5558 }
7780 options.quiet = true;
7881 } else if arg == "--loud" || arg == "-L" {
7982 options.loud = true;
83+ } else if arg == "--bye" {
84+ options.bye = true;
8085 } else if arg == "--times" {
8186 let value = args
8287 .next()
146151 }
147152
148153 #[test]
154+ fn parse_args_bye() {
155+ assert!(parse_args(args(&["--bye", "Ada"])).unwrap().bye);
156+ assert!(!parse_args(args(&["Ada"])).unwrap().bye);
157+ }
158+
159+ #[test]
149160 fn parse_args_loud() {
150161 assert!(parse_args(args(&["--loud", "Ada"])).unwrap().loud);
151162 assert!(parse_args(args(&["-L", "Ada"])).unwrap().loud);
+4−1
11 use std::{env, process};
22
3−use hello::{greeting_in, loud, parse_args, shout};
3+use hello::{farewell, greeting_in, loud, parse_args, shout};
44
55 fn main() {
66 let options = match parse_args(env::args().skip(1)) {
2828 for _ in 0..options.times {
2929 println!("{line}");
3030 }
31+ if options.bye {
32+ println!("{}", farewell(&name));
33+ }
3134 }