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
use crate::style::Style;

pub trait Format: From<Style> {
    fn set_style(&mut self, style: Style);

    fn current_style(&self) -> &Style;

    fn format_usage_name(&self, name: &str) -> String {
        format!("usage: {} ", name)
    }

    fn format_usage_opt(&self, hint: &str, optional: bool) -> String {
        if optional {
            format!("[{}] ", hint)
        } else {
            format!("<{}> ", hint)
        }
    }

    fn format_usage_cmd(&self, cmd: Option<&str>) -> String {
        if let Some(cmd_name) = cmd {
            format!("{} ", cmd_name)
        } else {
            String::from("<COMMAND> ")
        }
    }

    fn format_usage_pos(&self, pos_count: usize) -> String {
        if pos_count > 0 {
            String::from("**ARGS**")
        } else {
            String::default()
        }
    }

    fn get_opt_title(&self) -> String {
        String::from("\nOPT:\n")
    }

    fn format_opt_line(&self, rows: &Vec<String>) -> String {
        rows.join(&" ".repeat(self.current_style().row_spacing))
    }

    fn format_opt_new_line(&self) -> String {
        format!("\n{}", "\n".repeat(self.current_style().opt_line_spacing))
    }

    fn get_pos_title(&self) -> String {
        String::from("\nPOS:\n")
    }

    fn format_pos_line(&self, rows: &Vec<String>) -> String {
        rows.join(&" ".repeat(self.current_style().row_spacing))
    }

    fn format_pos_new_line(&self) -> String {
        format!("\n{}", "\n".repeat(self.current_style().pos_line_spacing))
    }

    fn format_sec_title(&self, help: &str) -> String {
        format!("\n{}\n", help)
    }

    fn format_sec_line(&self, rows: &Vec<String>) -> String {
        rows.join(&" ".repeat(self.current_style().row_spacing))
    }

    fn format_sec_new_line(&self) -> String {
        format!("\n{}", "\n".repeat(self.current_style().cmd_line_spacing))
    }

    fn format_footer(&self, footer: &str) -> String {
        format!("\n{}\n", footer)
    }

    fn format_header(&self, header: &str) -> String {
        format!("\n{}\n", header)
    }
}