flagon-io/hello

public

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

hello/src/main.rs

45 lines1,060 bytesCodeBlame
1use std::{env, process};
2
3use hello::{greeting_in, loud, parse_args, part, 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 {
27 loud(&message)
28 } else {
29 message
30 };
31 let line = if options.shout {
32 shout(&message)
33 } else {
34 message
35 };
36 for _ in 0..options.times {
37 println!("{line}");
38 }
39 if options.wave {
40 println!("{}", wave());
41 }
42 if options.bye {
43 println!("{}", part(&name));
44 }
45}