aopt_help/
store.rs

1use std::borrow::Cow;
2
3use crate::format::{HelpDisplay, HelpPolicy};
4
5#[derive(Debug, Default, Clone)]
6pub struct Store<'a> {
7    name: Cow<'a, str>,
8
9    hint: Cow<'a, str>,
10
11    help: Cow<'a, str>,
12
13    r#type: Cow<'a, str>,
14
15    optional: bool,
16
17    position: bool,
18}
19
20impl<'a> Store<'a> {
21    pub fn new<S: Into<Cow<'a, str>>>(
22        name: S,
23        hint: S,
24        help: S,
25        r#type: S,
26        optional: bool,
27        position: bool,
28    ) -> Self {
29        Self {
30            name: name.into(),
31            hint: hint.into(),
32            help: help.into(),
33            r#type: r#type.into(),
34            optional,
35            position,
36        }
37    }
38
39    pub fn name(&self) -> Cow<'a, str> {
40        self.name.clone()
41    }
42
43    pub fn hint(&self) -> Cow<'a, str> {
44        self.hint.clone()
45    }
46
47    pub fn help(&self) -> Cow<'a, str> {
48        self.help.clone()
49    }
50
51    pub fn optional(&self) -> bool {
52        self.optional
53    }
54
55    pub fn position(&self) -> bool {
56        self.position
57    }
58
59    pub fn r#type(&self) -> Cow<'a, str> {
60        self.r#type.clone()
61    }
62
63    pub fn set_name<S: Into<Cow<'a, str>>>(&mut self, name: S) -> &mut Self {
64        self.name = name.into();
65        self
66    }
67
68    pub fn set_hint<S: Into<Cow<'a, str>>>(&mut self, hint: S) -> &mut Self {
69        self.hint = hint.into();
70        self
71    }
72
73    pub fn set_help<S: Into<Cow<'a, str>>>(&mut self, help: S) -> &mut Self {
74        self.help = help.into();
75        self
76    }
77
78    pub fn set_optional(&mut self, optional: bool) -> &mut Self {
79        self.optional = optional;
80        self
81    }
82
83    pub fn set_position(&mut self, position: bool) -> &mut Self {
84        self.position = position;
85        self
86    }
87
88    pub fn set_type<S: Into<Cow<'a, str>>>(&mut self, type_name: S) -> &mut Self {
89        self.r#type = type_name.into();
90        self
91    }
92}
93
94impl HelpDisplay for Store<'_> {
95    fn gen_help<'a, P>(&self, policy: &P) -> Option<Cow<'a, str>>
96    where
97        Self: 'a,
98        P: HelpPolicy<'a, Self>,
99    {
100        policy.format(self)
101    }
102}