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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use clap::Parser;

struct Trapezoid {
    s_base: f32,
    l_base: f32,
    height: f32,
}

impl Trapezoid {
    fn get_area(&self) -> f32 {
        ((&self.l_base + &self.s_base) * &self.height) / 2.0
    }
}

pub fn trapezoid_actions(s_base: f32, l_base: f32, height: f32, area: bool) {
    let trapezoid = Trapezoid {
        height,
        l_base,
        s_base,
    };

    if area {
        println!("Area: {}cm", trapezoid.get_area())
    }
}

#[derive(Parser)]
#[command(about="Mathematical operations with trapezoids", long_about = None)]
pub struct Command {
    #[arg(
        short = 'l',
        long = "larger-base",
        help = "Sets the Larger Base of the trapezoid | e.g. --larger-base 5"
    )]
    pub l_base: f32,
    #[arg(
        short = 's',
        long = "smaller-base",
        help = "Sets the Smaller Base of the trapezoid | e.g. --smaller-base 5"
    )]
    pub s_base: f32,
    #[arg(
        short = 'e',
        long,
        help = "Sets the hEight of the trapezoid | e.g. -e 5"
    )]
    pub height: f32,

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

#[cfg(test)]
mod test {
    #[test]
    fn get_area() {
        let trapezoid = super::Trapezoid {
            s_base: 42.0,
            l_base: 42.0,
            height: 42.0,
        };

        assert_eq!(trapezoid.get_area(), 1764.0);
    }
}