flagon-io/hello

public

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

Add a --wave flag #68

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

2 files+25−10/2 viewed
+21−0
4040 pub loud: bool,
4141 /// Whether to print a goodbye after the greeting (`--bye`).
4242 pub bye: bool,
43+ /// Whether to print a wave after the greeting (`--wave`).
44+ pub wave: bool,
4345 }
4446
4547 impl Default for Options {
5355 quiet: false,
5456 loud: false,
5557 bye: false,
58+ wave: false,
5659 }
5760 }
5861 }
8285 options.loud = true;
8386 } else if arg == "--bye" {
8487 options.bye = true;
88+ } else if arg == "--wave" {
89+ options.wave = true;
8590 } else if arg == "--times" {
8691 let value = args
8792 .next()
129134 }
130135 }
131136
137+/// The wave printed by `--wave`.
138+pub fn wave() -> &'static str {
139+ "o/"
140+}
141+
132142 /// The farewell for `name`.
133143 pub fn part(name: &str) -> String {
134144 let trimmed = name.trim();
157167 }
158168
159169 #[test]
170+ fn parse_args_wave() {
171+ assert!(parse_args(args(&["--wave", "Ada"])).unwrap().wave);
172+ assert!(!parse_args(args(&["Ada"])).unwrap().wave);
173+ }
174+
175+ #[test]
176+ fn wave_is_o_slash() {
177+ assert_eq!(wave(), "o/");
178+ }
179+
180+ #[test]
160181 fn parse_args_loud() {
161182 assert!(parse_args(args(&["--loud", "Ada"])).unwrap().loud);
162183 assert!(parse_args(args(&["-L", "Ada"])).unwrap().loud);
+4−1
11 use std::{env, process};
22
3−use hello::{greeting_in, loud, parse_args, part, shout};
3+use hello::{greeting_in, loud, parse_args, part, shout, wave};
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.wave {
32+ println!("{}", wave());
33+ }
3134 if options.bye {
3235 println!("{}", part(&name));
3336 }