Add a --both flag #89
Mergedg1tbot merged into maing1t-agenton g1t
Approved by g1t-agent
3 files+17−00/3 viewed
| 15 | 15 | | `--lang LANG` | Greets in the given language. Supported values are `en`, `es` and `fr`. Defaults to `en`. | | |
| 16 | 16 | | `--loud`, `-L` | Ends the greeting with `!!!` instead of `!`. | | |
| 17 | 17 | | `--bye` | Prints `Goodbye, NAME!` after the greeting. | | |
| 18 | + | | `--both` | Prints the greeting and `Goodbye, NAME!` on one line. | | |
| 18 | 19 | | `--wave` | Prints `o/` after the greeting. | | |
| 19 | 20 | | `--quiet` | Prints no greeting at all. `--version` still prints the version. | | |
| 20 | 21 |
| 46 | 46 | pub bye: bool, | |
| 47 | 47 | /// Whether to print a wave after the greeting (`--wave`). | |
| 48 | 48 | pub wave: bool, | |
| 49 | + | /// Whether to print the greeting and a goodbye on one line (`--both`). | |
| 50 | + | pub both: bool, | |
| 49 | 51 | } | |
| 50 | 52 | ||
| 51 | 53 | impl Default for Options { | |
| 62 | 64 | loud: false, | |
| 63 | 65 | bye: false, | |
| 64 | 66 | wave: false, | |
| 67 | + | both: false, | |
| 65 | 68 | } | |
| 66 | 69 | } | |
| 67 | 70 | } | |
| 99 | 102 | options.bye = true; | |
| 100 | 103 | } else if arg == "--wave" { | |
| 101 | 104 | options.wave = true; | |
| 105 | + | } else if arg == "--both" { | |
| 106 | + | options.both = true; | |
| 102 | 107 | } else if arg == "--times" { | |
| 103 | 108 | let value = args | |
| 104 | 109 | .next() | |
| 195 | 200 | } | |
| 196 | 201 | ||
| 197 | 202 | #[test] | |
| 203 | + | fn parse_args_both() { | |
| 204 | + | assert!(parse_args(args(&["--both", "Ada"])).unwrap().both); | |
| 205 | + | assert!(!parse_args(args(&["Ada"])).unwrap().both); | |
| 206 | + | } | |
| 207 | + | ||
| 208 | + | #[test] | |
| 198 | 209 | fn wave_is_o_slash() { | |
| 199 | 210 | assert_eq!(wave(), "o/"); | |
| 200 | 211 | } |
| 40 | 40 | } else { | |
| 41 | 41 | message | |
| 42 | 42 | }; | |
| 43 | + | let line = if options.both { | |
| 44 | + | format!("{line} {}", part(&name)) | |
| 45 | + | } else { | |
| 46 | + | line | |
| 47 | + | }; | |
| 43 | 48 | for _ in 0..options.times { | |
| 44 | 49 | println!("{line}"); | |
| 45 | 50 | } |