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
use clap::Parser;

struct Rhombus {
    s_diagonal: f32,
    l_diagonal: f32,
}

impl Rhombus {
    fn get_area(&self) -> f32 {
        (&self.s_diagonal * &self.l_diagonal) / 2.0
    }
}

pub fn rhombus_actions(s_diagonal: f32, l_diagonal: f32, area: bool) {
    let rhombus = Rhombus {
        l_diagonal,
        s_diagonal,
    };

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

#[derive(Parser)]
#[command(about="Mathematical operations with rhombus", long_about = None)]
pub struct Command {
    #[arg(
        short = 'l',
        long = "larger-diagonal",
        help = "Sets the Larger diagonal of the rhombus | e.g. --larger-diagonal 5"
    )]
    pub l_diagonal: f32,
    #[arg(
        short = 's',
        long = "smaller-diagonal",
        help = "Sets the Smaller diagonal of the rhombus | e.g. --smaller-diagonal 5"
    )]
    pub s_diagonal: f32,

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

#[cfg(test)]
mod test {

    #[test]
    fn get_area() {
        let rhombus = super::Rhombus {
            s_diagonal: 42.0,
            l_diagonal: 42.0,
        };

        assert_eq!(rhombus.get_area(), 882.0);
    }
}