flagon-io/hello

public

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

hello/src/main.rs

37 lines1,020 bytesCodeBlame
1use std::{env, process};
2
3use hello::{farewell, greeting_in, loud, parse_args, shout, wave};
4
5fn main() {
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 };
13 if options.version {
14 println!("{}", env!("CARGO_PKG_VERSION"));
15 return;
16 }
17 if options.quiet {
18 return;
19 }
20 // The name given, or whoever is signed in.
21 let name = options
22 .name
23 .or_else(|| env::var("USER").ok())
24 .unwrap_or_else(|| "world".to_owned());
25 let message = greeting_in(&name, options.lang);
26 let message = if options.loud { loud(&message) } else { message };
27 let line = if options.shout { shout(&message) } else { message };
28 for _ in 0..options.times {
29 println!("{line}");
30 }
31 if options.wave {
32 println!("{}", wave());
33 }
34 if options.bye {
35 println!("{}", farewell(&name));
36 }
37}