@@ -34,6 +34,33 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
3434 .multiple(true)
3535 .empty_values(false),
3636 )
37+ .arg(
38+ Arg::with_name("show-all")
39+ .long("show-all")
40+ .alias("show-nonprintable")
41+ .short("A")
42+ .conflicts_with("language")
43+ .help("Show non-printable characters (space, tab, newline, ..).")
44+ .long_help(
45+ "Show non-printable characters like space, tab or newline. \
46+ This option can also be used to print binary files. \
47+ Use '--tabs' to control the width of the tab-placeholders."
48+ ),
49+ )
50+ .arg(
51+ Arg::with_name("plain")
52+ .overrides_with("plain")
53+ .overrides_with("number")
54+ .short("p")
55+ .long("plain")
56+ .multiple(true)
57+ .help("Show plain style (alias for '--style=plain').")
58+ .long_help(
59+ "Only show plain style, no decorations. This is an alias for \
60+ '--style=plain'. When '-p' is used twice ('-pp'), it also disables \
61+ automatic paging (alias for '--style=plain --pager=never').",
62+ ),
63+ )
3764 .arg(
3865 Arg::with_name("language")
3966 .short("l")
@@ -49,103 +76,75 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
4976 .takes_value(true),
5077 )
5178 .arg(
52− Arg::with_name("list-languages")
53− .long("list-languages")
54− .short("L")
55− .conflicts_with("list-themes")
56− .help("Display all supported languages.")
57− .long_help("Display a list of supported languages for syntax highlighting."),
58− )
59− .arg(
60− Arg::with_name("map-syntax")
61− .short("m")
62− .long("map-syntax")
63− .multiple(true)
79+ Arg::with_name("highlight-line")
80+ .long("highlight-line")
81+ .short("H")
6482 .takes_value(true)
6583 .number_of_values(1)
66− .value_name("from:to")
67− .help("Map a file extension or name to an existing syntax.")
84+ .multiple(true)
85+ .value_name("N")
86+ .help("Highlight the given line.")
6887 .long_help(
69− "Map a file extension or file name to an existing syntax. For example, \
70− to highlight *.conf files with the INI syntax, use '-m conf:ini'. \
71− To highlight files named '.myignore' with the Git Ignore syntax, use \
72− '-m .myignore:gitignore'.",
73− )
74− .takes_value(true),
88+ "Highlight the N-th line with a different background color",
89+ ),
7590 )
7691 .arg(
77− Arg::with_name("theme")
78− .long("theme")
79− .overrides_with("theme")
92+ Arg::with_name("tabs")
93+ .long("tabs")
94+ .overrides_with("tabs")
8095 .takes_value(true)
81− .help("Set the color theme for syntax highlighting.")
96+ .value_name("T")
97+ .validator(
98+ |t| {
99+ t.parse::<u32>()
100+ .map_err(|_t| "must be a number")
101+ .map(|_t| ()) // Convert to Result<(), &str>
102+ .map_err(|e| e.to_string())
103+ }, // Convert to Result<(), String>
104+ )
105+ .help("Set the tab width to T spaces.")
82106 .long_help(
83− "Set the theme for syntax highlighting. Use '--list-themes' to \
84− see all available themes. To set a default theme, add the \
85− '--theme=\"...\"' option to the configuration file or export the \
86− BAT_THEME environment variable (e.g.: export \
87− BAT_THEME=\"...\").",
107+ "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
108+ directly",
88109 ),
89110 )
90111 .arg(
91− Arg::with_name("list-themes")
92− .long("list-themes")
93− .help("Display all supported highlighting themes.")
94− .long_help("Display a list of supported themes for syntax highlighting."),
112+ Arg::with_name("wrap")
113+ .long("wrap")
114+ .overrides_with("wrap")
115+ .takes_value(true)
116+ .value_name("mode")
117+ .possible_values(&["auto", "never", "character"])
118+ .default_value("auto")
119+ .hide_default_value(true)
120+ .help("Specify the text-wrapping mode (*auto*, never, character).")
121+ .long_help("Specify the text-wrapping mode (*auto*, never, character). \
122+ The '--terminal-width' option can be used in addition to \
123+ control the output width."),
95124 )
96125 .arg(
97− Arg::with_name("style")
98− .long("style")
99− .value_name("style-components")
100− // Need to turn this off for overrides_with to work as we want. See the bottom most
101− // example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
102− .use_delimiter(false)
126+ Arg::with_name("terminal-width")
127+ .long("terminal-width")
103128 .takes_value(true)
104− .overrides_with("style")
105− .overrides_with("plain")
106− .overrides_with("number")
107− // Cannot use clap's built in validation because we have to turn off clap's delimiters
108− .validator(|val| {
109− let mut invalid_vals = val.split(',').filter(|style| {
110− !&[
111− "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
112− ]
113− .contains(style)
114− });
115−
116− if let Some(invalid) = invalid_vals.next() {
117− Err(format!("Unknown style, '{}'", invalid))
118− } else {
119− Ok(())
120− }
121− })
129+ .value_name("width")
130+ .hidden_short_help(true)
131+ .allow_hyphen_values(true)
132+ .validator(
133+ |t| {
134+ let is_offset = t.starts_with('+') || t.starts_with('-');
135+ t.parse::<i32>()
136+ .map_err(|_e| "must be an offset or number")
137+ .and_then(|v| if v == 0 && !is_offset {
138+ Err("terminal width cannot be zero".into())
139+ } else {
140+ Ok(())
141+ })
142+ .map_err(|e| e.to_string())
143+ })
122144 .help(
123− "Comma-separated list of style elements to display \
124− (*auto*, full, plain, changes, header, grid, numbers, snip).",
125− )
126− .long_help(
127− "Configure which elements (line numbers, file headers, grid \
128− borders, Git modifications, ..) to display in addition to the \
129− file contents. The argument is a comma-separated list of \
130− components to display (e.g. 'numbers,changes,grid') or a \
131− pre-defined style ('full'). To set a default style, add the \
132− '--style=\"..\"' option to the configuration file or export the \
133− BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\"). \
134− Possible values: *auto*, full, plain, changes, header, grid, numbers, snip.",
135− ),
136− )
137− .arg(
138− Arg::with_name("plain")
139− .overrides_with("plain")
140− .overrides_with("number")
141− .short("p")
142− .long("plain")
143− .multiple(true)
144− .help("Show plain style (alias for '--style=plain').")
145− .long_help(
146− "Only show plain style, no decorations. This is an alias for \
147− '--style=plain'. When '-p' is used twice ('-pp'), it also disables \
148− automatic paging (alias for '--style=plain --pager=never').",
145+ "Explicitly set the width of the terminal instead of determining it \
146+ automatically. If prefixed with '+' or '-', the value will be treated \
147+ as an offset to the actual terminal width. See also: '--wrap'.",
149148 ),
150149 )
151150 .arg(
@@ -159,49 +158,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
159158 '--style=numbers'",
160159 ),
161160 )
162− .arg(
163− Arg::with_name("show-all")
164− .long("show-all")
165− .alias("show-nonprintable")
166− .short("A")
167− .conflicts_with("language")
168− .help("Show non-printable characters (space, tab, newline, ..).")
169− .long_help(
170− "Show non-printable characters like space, tab or newline. \
171− This option can also be used to print binary files. \
172− Use '--tabs' to control the width of the tab-placeholders."
173− ),
174− )
175− .arg(
176− Arg::with_name("line-range")
177− .long("line-range")
178− .short("r")
179− .multiple(true)
180− .takes_value(true)
181− .number_of_values(1)
182− .value_name("N:M")
183− .help("Only print the lines from N to M.")
184− .long_help(
185− "Only print the specified range of lines for each file. \
186− For example:\n \
187− '--line-range 30:40' prints lines 30 to 40\n \
188− '--line-range :40' prints lines 1 to 40\n \
189− '--line-range 40:' prints lines 40 to the end of the file",
190− ),
191− )
192− .arg(
193− Arg::with_name("highlight-line")
194− .long("highlight-line")
195− .short("H")
196− .takes_value(true)
197− .number_of_values(1)
198− .multiple(true)
199− .value_name("N")
200− .help("Highlight the given line.")
201− .long_help(
202− "Highlight the N-th line with a different background color",
203− ),
204− )
205161 .arg(
206162 Arg::with_name("color")
207163 .long("color")
@@ -281,39 +237,108 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
281237 ),
282238 )
283239 .arg(
284− Arg::with_name("wrap")
285− .long("wrap")
286− .overrides_with("wrap")
240+ Arg::with_name("map-syntax")
241+ .short("m")
242+ .long("map-syntax")
243+ .multiple(true)
287244 .takes_value(true)
288− .value_name("mode")
289− .possible_values(&["auto", "never", "character"])
290− .default_value("auto")
291− .hide_default_value(true)
292− .help("Specify the text-wrapping mode (*auto*, never, character).")
293− .long_help("Specify the text-wrapping mode (*auto*, never, character). \
294− The '--terminal-width' option can be used in addition to \
295− control the output width."),
245+ .number_of_values(1)
246+ .value_name("from:to")
247+ .help("Map a file extension or name to an existing syntax.")
248+ .long_help(
249+ "Map a file extension or file name to an existing syntax. For example, \
250+ to highlight *.conf files with the INI syntax, use '-m conf:ini'. \
251+ To highlight files named '.myignore' with the Git Ignore syntax, use \
252+ '-m .myignore:gitignore'.",
253+ )
254+ .takes_value(true),
296255 )
297256 .arg(
298− Arg::with_name("tabs")
299− .long("tabs")
300− .overrides_with("tabs")
257+ Arg::with_name("theme")
258+ .long("theme")
259+ .overrides_with("theme")
301260 .takes_value(true)
302− .value_name("T")
303− .validator(
304− |t| {
305− t.parse::<u32>()
306− .map_err(|_t| "must be a number")
307− .map(|_t| ()) // Convert to Result<(), &str>
308− .map_err(|e| e.to_string())
309− }, // Convert to Result<(), String>
261+ .help("Set the color theme for syntax highlighting.")
262+ .long_help(
263+ "Set the theme for syntax highlighting. Use '--list-themes' to \
264+ see all available themes. To set a default theme, add the \
265+ '--theme=\"...\"' option to the configuration file or export the \
266+ BAT_THEME environment variable (e.g.: export \
267+ BAT_THEME=\"...\").",
268+ ),
269+ )
270+ .arg(
271+ Arg::with_name("list-themes")
272+ .long("list-themes")
273+ .help("Display all supported highlighting themes.")
274+ .long_help("Display a list of supported themes for syntax highlighting."),
275+ )
276+ .arg(
277+ Arg::with_name("style")
278+ .long("style")
279+ .value_name("style-components")
280+ // Need to turn this off for overrides_with to work as we want. See the bottom most
281+ // example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
282+ .use_delimiter(false)
283+ .takes_value(true)
284+ .overrides_with("style")
285+ .overrides_with("plain")
286+ .overrides_with("number")
287+ // Cannot use clap's built in validation because we have to turn off clap's delimiters
288+ .validator(|val| {
289+ let mut invalid_vals = val.split(',').filter(|style| {
290+ !&[
291+ "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
292+ ]
293+ .contains(style)
294+ });
295+
296+ if let Some(invalid) = invalid_vals.next() {
297+ Err(format!("Unknown style, '{}'", invalid))
298+ } else {
299+ Ok(())
300+ }
301+ })
302+ .help(
303+ "Comma-separated list of style elements to display \
304+ (*auto*, full, plain, changes, header, grid, numbers, snip).",
310305 )
311− .help("Set the tab width to T spaces.")
312306 .long_help(
313− "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
314− directly",
307+ "Configure which elements (line numbers, file headers, grid \
308+ borders, Git modifications, ..) to display in addition to the \
309+ file contents. The argument is a comma-separated list of \
310+ components to display (e.g. 'numbers,changes,grid') or a \
311+ pre-defined style ('full'). To set a default style, add the \
312+ '--style=\"..\"' option to the configuration file or export the \
313+ BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\"). \
314+ Possible values: *auto*, full, plain, changes, header, grid, numbers, snip.",
315315 ),
316316 )
317+ .arg(
318+ Arg::with_name("line-range")
319+ .long("line-range")
320+ .short("r")
321+ .multiple(true)
322+ .takes_value(true)
323+ .number_of_values(1)
324+ .value_name("N:M")
325+ .help("Only print the lines from N to M.")
326+ .long_help(
327+ "Only print the specified range of lines for each file. \
328+ For example:\n \
329+ '--line-range 30:40' prints lines 30 to 40\n \
330+ '--line-range :40' prints lines 1 to 40\n \
331+ '--line-range 40:' prints lines 40 to the end of the file",
332+ ),
333+ )
334+ .arg(
335+ Arg::with_name("list-languages")
336+ .long("list-languages")
337+ .short("L")
338+ .conflicts_with("list-themes")
339+ .help("Display all supported languages.")
340+ .long_help("Display a list of supported languages for syntax highlighting."),
341+ )
317342 .arg(
318343 Arg::with_name("unbuffered")
319344 .short("u")
@@ -325,31 +350,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
325350 is simply ignored.",
326351 ),
327352 )
328− .arg(
329− Arg::with_name("terminal-width")
330− .long("terminal-width")
331− .takes_value(true)
332− .value_name("width")
333− .hidden_short_help(true)
334− .allow_hyphen_values(true)
335− .validator(
336− |t| {
337− let is_offset = t.starts_with('+') || t.starts_with('-');
338− t.parse::<i32>()
339− .map_err(|_e| "must be an offset or number")
340− .and_then(|v| if v == 0 && !is_offset {
341− Err("terminal width cannot be zero".into())
342− } else {
343− Ok(())
344− })
345− .map_err(|e| e.to_string())
346− })
347− .help(
348− "Explicitly set the width of the terminal instead of determining it \
349− automatically. If prefixed with '+' or '-', the value will be treated \
350− as an offset to the actual terminal width. See also: '--wrap'.",
351− ),
352− )
353353 .arg(
354354 Arg::with_name("no-config")
355355 .long("no-config")