diff2html/
config.rs

1use std::convert::From;
2
3use clap::ArgMatches;
4
5impl Default for Diff2HtmlConfig {
6    fn default() -> Diff2HtmlConfig {
7        Diff2HtmlConfig {
8            input: "command".to_owned(),
9            output: "stdout".to_owned(),
10            diff: "smartword".to_owned(),
11            style: "line".to_owned(),
12            synchronized_scroll: "enabled".to_owned(),
13            summary: "closed".to_owned(),
14            matching: "none".to_owned(),
15            match_words_threshold: 0.25f64,
16            matching_max_comparisons: 2500,
17            file: None,
18            format: "html".to_owned(),
19            is_combined: false,
20            max_line_length_highlight: 10000,
21            word_by_word: true,
22            char_by_char: false,
23            trail: None,
24        }
25    }
26}
27
28#[derive(Clone)]
29pub struct Diff2HtmlConfig {
30    pub input: String,
31    pub output: String,
32    pub diff: String,
33    pub style: String,
34    pub synchronized_scroll: String,
35    pub summary: String,
36    pub matching: String,
37    pub match_words_threshold: f64,
38    pub matching_max_comparisons: usize,
39    pub file: Option<String>,
40    pub format: String,
41    pub is_combined: bool,
42    pub max_line_length_highlight: usize,
43    pub word_by_word: bool,
44    pub char_by_char: bool,
45    pub trail: Option<Vec<String>>,
46}
47
48impl<'a> From<ArgMatches<'a>> for Diff2HtmlConfig {
49    fn from(matches: ArgMatches<'a>) -> Diff2HtmlConfig {
50        let mut config = Diff2HtmlConfig::default();
51
52        // input
53        if let Some(input) = matches.value_of("input") {
54            config.input = input.to_owned();
55        }
56
57        // file
58        if let Some(file) = matches.value_of("file") {
59            config.file = Some(file.to_owned());
60        }
61
62        // format
63        if let Some(format) = matches.value_of("format") {
64            config.format = format.to_owned();
65        }
66
67        // output
68        if let Some(output) = matches.value_of("output") {
69            config.output = output.to_owned();
70        }
71
72        // diff
73        if let Some(diff) = matches.value_of("diff") {
74            config.diff = diff.to_owned();
75        }
76
77        // style
78        if let Some(style) = matches.value_of("style") {
79            config.style = style.to_owned();
80        }
81
82        // synchronized_scroll
83        if let Some(synchronized_scroll) = matches.value_of("synchronized_scroll") {
84            config.synchronized_scroll = synchronized_scroll.to_owned();
85        }
86
87        // summary
88        if let Some(summary) = matches.value_of("summary") {
89            config.summary = summary.to_owned();
90        }
91
92        // matching
93        if let Some(matching) = matches.value_of("matching") {
94            config.matching = matching.to_owned();
95        }
96
97        // match_words_threshold
98        if let Some(match_words_threshold) = matches.value_of("match_words_threshold") {
99            config.match_words_threshold = match_words_threshold
100                .parse()
101                .expect("Match words threshold is not in float format.");
102        }
103
104        // matching_max_comparisons
105        if let Some(matching_max_comparisons) = matches.value_of("matching_max_comparisons") {
106            config.matching_max_comparisons = matching_max_comparisons
107                .parse()
108                .expect("Match words threshold is not in unsigned integer format.");
109        }
110
111        config.trail = matches
112            .values_of("trail")
113            .map(|v| v.map(|v| v.to_owned()).collect());
114
115        config
116    }
117}