on master help sign in
Run 'cargo fmt'
commit268577c6f99fda02c79715bc93a69655732d1d4c authorsharkdp <davidpeter@web.de> dateSat 18 Aug 2018, 17:39 (8 years ago) parent037861e
3 files changed+39−57
src/app.rs+24−48 src/features.rs+13−5 src/printer.rs+2−4
src/app.rs+24−48
@@ -48,8 +48,7 @@ impl App {
4848 .about(
4949 "A cat(1) clone with wings.\n\n\
5050 Use '--help' instead of '-h' to see a more detailed version of the help text.",
51− )
52− .long_about("A cat(1) clone with syntax highlighting and Git integration.")
51+ ).long_about("A cat(1) clone with syntax highlighting and Git integration.")
5352 .arg(
5453 Arg::with_name("language")
5554 .short("l")
@@ -61,20 +60,16 @@ impl App {
6160 specified as a name (like 'C++' or 'LaTeX') or possible file \
6261 extension (like 'cpp', 'hpp' or 'md'). Use '--list-languages' \
6362 to show all supported language names and file extensions",
64− )
65− .takes_value(true),
66− )
67− .arg(
63+ ).takes_value(true),
64+ ).arg(
6865 Arg::with_name("FILE")
6966 .help("File(s) to print / concatenate. Use '-' for standard input.")
7067 .long_help(
7168 "File(s) to print. Use no argument or '-' to read from standard \
7269 input",
73− )
74− .multiple(true)
70+ ).multiple(true)
7571 .empty_values(false),
76− )
77− .arg(
72+ ).arg(
7873 Arg::with_name("style")
7974 .long("style")
8075 .value_name("style-components")
@@ -82,8 +77,7 @@ impl App {
8277 .takes_value(true)
8378 .possible_values(&[
8479 "auto", "full", "plain", "changes", "header", "grid", "numbers",
85− ])
86− .default_value("auto")
80+ ]).default_value("auto")
8781 .help("Comma-separated list of style elements to display")
8882 .long_help(
8983 "Configure which elements (line numbers, file headers, grid \
@@ -92,8 +86,7 @@ impl App {
9286 components to display (e.g. 'numbers,changes,grid') or a \
9387 pre-defined style ('full')",
9488 ),
95− )
96− .arg(
89+ ).arg(
9790 Arg::with_name("color")
9891 .long("color")
9992 .overrides_with("color")
@@ -102,8 +95,7 @@ impl App {
10295 .possible_values(&["auto", "never", "always"])
10396 .default_value("auto")
10497 .help("When to use colors"),
105− )
106− .arg(
98+ ).arg(
10799 Arg::with_name("paging")
108100 .long("paging")
109101 .overrides_with("paging")
@@ -113,8 +105,7 @@ impl App {
113105 .default_value("auto")
114106 .help("When to use the pager")
115107 .long_help("Specify when to use the pager (less)"),
116− )
117− .arg(
108+ ).arg(
118109 Arg::with_name("wrap")
119110 .long("wrap")
120111 .overrides_with("wrap")
@@ -123,14 +114,12 @@ impl App {
123114 .possible_values(&["character", "never"])
124115 .default_value("character")
125116 .help("When to wrap text"),
126− )
127− .arg(
117+ ).arg(
128118 Arg::with_name("list-languages")
129119 .long("list-languages")
130120 .help("Displays supported languages")
131121 .long_help("Display a list of supported languages"),
132− )
133− .arg(
122+ ).arg(
134123 Arg::with_name("theme")
135124 .long("theme")
136125 .overrides_with("theme")
@@ -140,8 +129,7 @@ impl App {
140129 "Set the theme for syntax highlighting. Use '--list-themes' to \
141130 see all available themes",
142131 ),
143− )
144− .arg(
132+ ).arg(
145133 Arg::with_name("line-range")
146134 .long("line-range")
147135 .overrides_with("line-range")
@@ -154,14 +142,12 @@ impl App {
154142 '--line-range :40' will print lines 1 to 40 \n\
155143 '--line-range 40:' will print lines 40 to the end of the file",
156144 ),
157− )
158− .arg(
145+ ).arg(
159146 Arg::with_name("list-themes")
160147 .long("list-themes")
161148 .help("Displays supported themes")
162149 .help("Display a list of supported themes for syntax highlighting"),
163− )
164− .arg(
150+ ).arg(
165151 Arg::with_name("number")
166152 .long("number")
167153 .overrides_with("number")
@@ -172,8 +158,7 @@ impl App {
172158 "Show line numbers (no other decorations). This is an alias for \
173159 '--style=numbers'",
174160 ),
175− )
176− .arg(
161+ ).arg(
177162 Arg::with_name("unbuffered")
178163 .short("u")
179164 .help("(ignored)")
@@ -183,8 +168,7 @@ impl App {
183168 'unbuffered'). The output is always unbuffered - this option \
184169 is simply ignored.",
185170 ),
186− )
187− .subcommand(
171+ ).subcommand(
188172 SubCommand::with_name("cache")
189173 .about("Modify the syntax-definition and theme cache")
190174 .arg(
@@ -196,33 +180,28 @@ impl App {
196180 "Initialize the syntax/theme cache by loading from the \
197181 source directory (default: the configuration directory)",
198182 ),
199− )
200− .arg(
183+ ).arg(
201184 Arg::with_name("clear")
202185 .long("clear")
203186 .short("c")
204187 .help("Reset the cache"),
205− )
206− .arg(
188+ ).arg(
207189 Arg::with_name("config-dir")
208190 .long("config-dir")
209191 .short("d")
210192 .help("Show the configuration directory"),
211− )
212− .group(
193+ ).group(
213194 ArgGroup::with_name("cache-actions")
214195 .args(&["init", "clear", "config-dir"])
215196 .required(true),
216− )
217− .arg(
197+ ).arg(
218198 Arg::with_name("source")
219199 .long("source")
220200 .requires("init")
221201 .takes_value(true)
222202 .value_name("dir")
223203 .help("Use a different source for loading syntaxes and themes from"),
224− )
225− .arg(
204+ ).arg(
226205 Arg::with_name("target")
227206 .long("target")
228207 .requires("init")
@@ -232,8 +211,7 @@ impl App {
232211 "Use a different source to store the cached syntax and theme set",
233212 ),
234213 ),
235− )
236− .help_message("Print this help message.")
214+ ).help_message("Print this help message.")
237215 .version_message("Show version information.")
238216 .get_matches()
239217 }
@@ -303,10 +281,8 @@ impl App {
303281 } else {
304282 Some(filename)
305283 }
306− })
307− .collect()
308− })
309− .unwrap_or_else(|| vec![None]) // read from stdin (None) if no args are given
284+ }).collect()
285+ }).unwrap_or_else(|| vec![None]) // read from stdin (None) if no args are given
310286 }
311287
312288 fn output_components(&self) -> Result<OutputComponents> {
src/features.rs+13−5
@@ -92,11 +92,19 @@ fn print_file(
9292 match filename {
9393 None => {
9494 let stdin = io::stdin(); // TODO: this is not always needed
95− print_file_ranges(printer, stdin.lock(), highlighter, &printer.config.line_range)?;
96− },
97− Some(filename) => {
98− print_file_ranges(printer, BufReader::new(File::open(filename)?), highlighter, &printer.config.line_range)?
99− },
95+ print_file_ranges(
96+ printer,
97+ stdin.lock(),
98+ highlighter,
99+ &printer.config.line_range,
100+ )?;
101+ }
102+ Some(filename) => print_file_ranges(
103+ printer,
104+ BufReader::new(File::open(filename)?),
105+ highlighter,
106+ &printer.config.line_range,
107+ )?,
100108 }
101109
102110 printer.print_footer()?;
src/printer.rs+2−4
@@ -153,8 +153,7 @@ impl<'a> Printer<'a> {
153153 text,
154154 true_color,
155155 colored_output,
156− ))
157− .collect::<Vec<_>>()
156+ )).collect::<Vec<_>>()
158157 .join("")
159158 )?;
160159 } else {
@@ -216,8 +215,7 @@ impl<'a> Printer<'a> {
216215 .iter()
217216 .map(|ref d| d
218217 .generate(self.line_number, true, self)
219− .text)
220− .collect::<Vec<String>>()
218+ .text).collect::<Vec<String>>()
221219 .join(" ")
222220 ))
223221 } else {