flagon-io/hello

public

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

hello/src/main.rs

27 lines754 bytesCodeBlame
1use std::{env, process};
2
3use hello::{greeting_in, parse_args, shout};
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 // The name given, or whoever is signed in.
18 let name = options
19 .name
20 .or_else(|| env::var("USER").ok())
21 .unwrap_or_else(|| "world".to_owned());
22 let message = greeting_in(&name, options.lang);
23 let line = if options.shout { shout(&message) } else { message };
24 for _ in 0..options.times {
25 println!("{line}");
26 }
27}