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
35
36
37
38
39
40
41
42
43
44
45
46
use clap::Parser;

struct Square {
    base: i32,
    height: i32,
}

impl Square {
    fn get_area(&self) -> i32 {
        self.base * self.height
    }
}

pub fn square_action(area: bool, base: i32, height: i32) {
    let square = Square { base, height };

    if area {
        println!("{}cm", square.get_area());
    }
}

#[derive(Parser)]
#[command(about="Mathematical operations with squares", long_about = None)]
pub struct Command {
    #[arg(short, long, help = "Sets the Base of the square | e.g. -b 5")]
    pub base: i32,

    #[arg(short = 'e', long, help = "Sets the hEight of the square | e.g. -e 5")]
    pub height: i32,

    #[arg(short, long, help = "Get the Area of the square")]
    pub area: bool,
}

#[cfg(test)]
mod test {
    #[test]
    fn get_area() {
        let square = super::Square {
            base: 42,
            height: 42,
        };

        assert_eq!(square.get_area(), 1764);
    }
}