flagon-io/hello

public

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

hello/src/main.rs

57 lines1,348 bytesCodeBlame

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 times1use std::{env, process};
Greet people from the command line2
Rename hail() and part() to greet() and farewell()3use hello::{farewell, greeting_in, loud, parse_args, reverse, shout, wave, whisper};
Greet people from the command line4
5fn main() {
Add --times N flag that prints the greeting N times6 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 exits13 if options.version {
14 println!("{}", env!("CARGO_PKG_VERSION"));
15 return;
16 }
Add --quiet flag that prints nothing17 if options.quiet {
18 return;
19 }
Greet people from the command line20 // The name given, or whoever is signed in.
Add --shout flag that upper-cases the greeting21 let name = options
Extract argument parsing into parse_args in lib.rs22 .name
Greet people from the command line23 .or_else(|| env::var("USER").ok())
24 .unwrap_or_else(|| "world".to_owned());
Format the --reverse call as rustfmt expects25 let name = if options.reverse {
26 reverse(&name)
27 } else {
28 name
29 };
Merge #53: Add a --lang option (en, es, fr) to the greeter30 let message = greeting_in(&name, options.lang);
Add CI workflow for formatting, lints and tests31 let message = if options.loud {
32 loud(&message)
33 } else {
34 message
35 };
36 let line = if options.shout {
37 shout(&message)
Add --whisper flag38 } else if options.whisper {
39 whisper(&message)
Add CI workflow for formatting, lints and tests40 } else {
41 message
42 };
Catch up with main43 let line = if options.both {
Use farewell() in the --both call44 format!("{line} {}", farewell(&name))
Catch up with main45 } else {
46 line
47 };
Add --times N flag that prints the greeting N times48 for _ in 0..options.times {
49 println!("{line}");
50 }
Add --wave flag that prints o/ after the greeting51 if options.wave {
52 println!("{}", wave());
53 }
Merge #64: Add a --bye flag54 if options.bye {
Rename hail() and part() to greet() and farewell()55 println!("{}", farewell(&name));
Merge #64: Add a --bye flag56 }
Greet people from the command line57}

This file's history is long; its oldest lines are credited to the oldest commit read.