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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::borrow::Cow;

use crate::format::{HelpDisplay, HelpPolicy};

#[derive(Debug, Default, Clone)]
pub struct Store<'a> {
    name: Cow<'a, str>,

    hint: Cow<'a, str>,

    help: Cow<'a, str>,

    r#type: Cow<'a, str>,

    optional: bool,

    position: bool,
}

impl<'a> Store<'a> {
    pub fn new<S: Into<Cow<'a, str>>>(
        name: S,
        hint: S,
        help: S,
        r#type: S,
        optional: bool,
        position: bool,
    ) -> Self {
        Self {
            name: name.into(),
            hint: hint.into(),
            help: help.into(),
            r#type: r#type.into(),
            optional,
            position,
        }
    }

    pub fn name(&self) -> Cow<'a, str> {
        self.name.clone()
    }

    pub fn hint(&self) -> Cow<'a, str> {
        self.hint.clone()
    }

    pub fn help(&self) -> Cow<'a, str> {
        self.help.clone()
    }

    pub fn optional(&self) -> bool {
        self.optional
    }

    pub fn position(&self) -> bool {
        self.position
    }

    pub fn r#type(&self) -> Cow<'a, str> {
        self.r#type.clone()
    }

    pub fn set_name<S: Into<Cow<'a, str>>>(&mut self, name: S) -> &mut Self {
        self.name = name.into();
        self
    }

    pub fn set_hint<S: Into<Cow<'a, str>>>(&mut self, hint: S) -> &mut Self {
        self.hint = hint.into();
        self
    }

    pub fn set_help<S: Into<Cow<'a, str>>>(&mut self, help: S) -> &mut Self {
        self.help = help.into();
        self
    }

    pub fn set_optional(&mut self, optional: bool) -> &mut Self {
        self.optional = optional;
        self
    }

    pub fn set_position(&mut self, position: bool) -> &mut Self {
        self.position = position;
        self
    }

    pub fn set_type<S: Into<Cow<'a, str>>>(&mut self, type_name: S) -> &mut Self {
        self.r#type = type_name.into();
        self
    }
}

impl<'b> HelpDisplay for Store<'b> {
    fn gen_help<'a, P>(&self, policy: &P) -> Option<Cow<'a, str>>
    where
        Self: 'a,
        P: HelpPolicy<'a, Self>,
    {
        policy.format(self)
    }
}