Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Add --times N flag that prints the greeting N times | 1 | use std::{env, process}; |
| Greet people from the command line | 2 | |
| Add --shout flag that upper-cases the greeting | 3 | use hello::{greeting, parse_args, shout}; |
| Greet people from the command line | 4 | |
| 5 | fn main() { | |
| Add --times N flag that prints the greeting N times | 6 | let options = match parse_args(env::args().skip(1)) { |
| 7 | Ok(options) => options, | |
| 8 | Err(message) => { | |
| 9 | eprintln!("error: {message}"); | |
| 10 | process::exit(2); | |
| 11 | } | |
| 12 | }; | |
| Add --version flag that prints the crate version and exits | 13 | if options.version { |
| 14 | println!("{}", env!("CARGO_PKG_VERSION")); | |
| 15 | return; | |
| 16 | } | |
| Greet people from the command line | 17 | // The name given, or whoever is signed in. |
| Add --shout flag that upper-cases the greeting | 18 | let name = options |
| Extract argument parsing into parse_args in lib.rs | 19 | .name |
| Greet people from the command line | 20 | .or_else(|| env::var("USER").ok()) |
| 21 | .unwrap_or_else(|| "world".to_owned()); | |
| Add --shout flag that upper-cases the greeting | 22 | let message = greeting(&name); |
| Add --times N flag that prints the greeting N times | 23 | let line = if options.shout { shout(&message) } else { message }; |
| 24 | for _ in 0..options.times { | |
| 25 | println!("{line}"); | |
| 26 | } | |
| Greet people from the command line | 27 | } |