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
use std::{
fmt,
};
use super::{Cfg, I18n, Opt};
pub struct Cmd<'a> {
name: &'a str,
docs: &'a str,
options: Option<&'a [&'a Opt<'a>]>,
}
impl<'a> Cmd<'a> {
pub fn new(name: &'a str, docs: &'a str, options: Option<&'a [&'a Opt<'a>]>) -> Self {
Self {
name,
docs,
options,
}
}
pub fn format(&self, cfg: &Cfg, i18n: &I18n, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let tab = cfg.tab_len().saturating_mul(cfg.tab_level().into());
f.write_str(&super::format(self.name, tab, cfg.columns()))?;
f.write_str(super::LINE_BREAK)?;
let cfg = cfg.increment_level();
let tab = cfg.tab_len().saturating_mul(cfg.tab_level().into());
f.write_str(&super::format(self.docs, tab, cfg.columns()))?;
f.write_str(super::LINE_BREAK)?;
if let Some(options) = self.options {
f.write_str(&super::format(i18n.options, tab, cfg.columns()))?;
f.write_str(super::LINE_BREAK)?;
let cfg = cfg.increment_level();
for option in options {
option.format(&cfg, &i18n, f)?;
}
}
Ok(())
}
}