summaryrefslogtreecommitdiff
path: root/rust/echor/src/main.rs
blob: 323d4c7980ad8bcb8eb234ad7052edb3dbe94feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use clap::{App, Arg};

/*
 * Lack of specified return value means the function will return an UNIT type
 */
fn main() {
    let matches = App::new("echor")
        .version("0.1.0")
        .author("Ronaldo curintiano")
        .about("echo rusty")
        .arg(
            Arg::with_name("text")
                .value_name("TEXT")
                .help("Input text")
                .required(true)
                .min_values(1),
        )
        .arg(
            Arg::with_name("omit_newline")
                .value_name("OMIT NEWLINE")
                .short("n")
                .help("Do not print newline")
                .takes_value(false),
        )
        .get_matches();

    let text = matches.values_of_lossy("text").unwrap().join(" ");
    let omit_newline :bool = matches.is_present("omit_newline");
    
    print!("{}{}",
        text,
        if omit_newline {""} else {"\n"});

}