bird_tool_utils_man/
flag.rs1use super::*;
2use roff::{bold, list};
3#[derive(Debug, Clone, Default)]
5pub struct Flag {
6 pub(crate) short: Option<String>,
7 pub(crate) long: Option<String>,
8 pub(crate) help: Option<String>,
9}
10
11impl Flag {
12 pub fn new() -> Self {
14 Self::default()
15 }
16
17 pub fn short(mut self, short: &str) -> Self {
19 self.short = Some(short.into());
20 self
21 }
22
23 pub fn long(mut self, long: &str) -> Self {
25 self.long = Some(long.into());
26 self
27 }
28
29 pub fn help(mut self, help: &str) -> Self {
31 self.help = Some(help.into());
32 self
33 }
34}
35
36impl FlagOrOption for Flag {
37 fn render(&self) -> String {
38 let mut args: Vec<String> = vec![];
39 if let Some(ref short) = self.short {
40 args.push(bold(&short));
41 }
42 if let Some(ref long) = self.long {
43 if !args.is_empty() {
44 args.push(", ".to_string());
45 }
46 args.push(bold(&long));
47 }
48 let desc = match self.help {
49 Some(ref desc) => desc.to_string(),
50 None => "".to_string(),
51 };
52 return list(&args, &[desc]);
53 }
54}