@@ -34,6 +34,33 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
34 .multiple(true)
34 .multiple(true)
35 .empty_values(false),
35 .empty_values(false),
38+ Arg::with_name("show-all")
40+ .alias("show-nonprintable")
42+ .conflicts_with("language")
43+ .help("Show non-printable characters (space, tab, newline, ..).")
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."
51+ Arg::with_name("plain")
52+ .overrides_with("plain")
53+ .overrides_with("number")
57+ .help("Show plain style (alias for '--style=plain').")
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').",
38 Arg::with_name("language")
65 Arg::with_name("language")
39 .short("l")
66 .short("l")
@@ -49,103 +76,75 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
49 .takes_value(true),
76 .takes_value(true),
52− Arg::with_name("list-languages")
79+ Arg::with_name("highlight-line")
53− .long("list-languages")
80+ .long("highlight-line")
55− .conflicts_with("list-themes")
56− .help("Display all supported languages.")
57− .long_help("Display a list of supported languages for syntax highlighting."),
60− Arg::with_name("map-syntax")
61− .short("m")
81+ .short("H")
64 .takes_value(true)
82 .takes_value(true)
65 .number_of_values(1)
83 .number_of_values(1)
66− .value_name("from:to")
85+ .value_name("N")
67− .help("Map a file extension or name to an existing syntax.")
86+ .help("Highlight the given line.")
68 .long_help(
87 .long_help(
69− "Map a file extension or file name to an existing syntax. For example, \
88+ "Highlight the N-th line with a different background color",
70− to highlight *.conf files with the INI syntax, use '-m conf:ini'. \
89+ ),
71− To highlight files named '.myignore' with the Git Ignore syntax, use \
72− '-m .myignore:gitignore'.",
77− Arg::with_name("theme")
92+ Arg::with_name("tabs")
78− .long("theme")
93+ .long("tabs")
79− .overrides_with("theme")
94+ .overrides_with("tabs")
80 .takes_value(true)
95 .takes_value(true)
81− .help("Set the color theme for syntax highlighting.")
96+ .value_name("T")
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>
105+ .help("Set the tab width to T spaces.")
82 .long_help(
106 .long_help(
83− "Set the theme for syntax highlighting. Use '--list-themes' to \
107+ "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
84− see all available themes. To set a default theme, add the \
108+ directly",
85− '--theme=\"...\"' option to the configuration file or export the \
86− BAT_THEME environment variable (e.g.: export \
87− BAT_THEME=\"...\").",
91− Arg::with_name("list-themes")
112+ Arg::with_name("wrap")
92− .long("list-themes")
113+ .long("wrap")
93− .help("Display all supported highlighting themes.")
114+ .overrides_with("wrap")
94− .long_help("Display a list of supported themes for syntax highlighting."),
115+ .takes_value(true)
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."),
97− Arg::with_name("style")
126+ Arg::with_name("terminal-width")
98− .long("style")
127+ .long("terminal-width")
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)
103 .takes_value(true)
128 .takes_value(true)
104− .overrides_with("style")
129+ .value_name("width")
105− .overrides_with("plain")
130+ .hidden_short_help(true)
106− .overrides_with("number")
131+ .allow_hyphen_values(true)
107− // Cannot use clap's built in validation because we have to turn off clap's delimiters
108− .validator(|val| {
132+ .validator(
109− let mut invalid_vals = val.split(',').filter(|style| {
133+ |t| {
110− !&[
134+ let is_offset = t.starts_with('+') || t.starts_with('-');
111− "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
135+ t.parse::<i32>()
112− ]
136+ .map_err(|_e| "must be an offset or number")
113− .contains(style)
137+ .and_then(|v| if v == 0 && !is_offset {
114− });
138+ Err("terminal width cannot be zero".into())
116− if let Some(invalid) = invalid_vals.next() {
117− Err(format!("Unknown style, '{}'", invalid))
118− } else {
139+ } else {
142+ .map_err(|e| e.to_string())
123− "Comma-separated list of style elements to display \
145+ "Explicitly set the width of the terminal instead of determining it \
124− (*auto*, full, plain, changes, header, grid, numbers, snip).",
146+ automatically. If prefixed with '+' or '-', the value will be treated \
125− )
147+ as an offset to the actual terminal width. See also: '--wrap'.",
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.",
138− Arg::with_name("plain")
139− .overrides_with("plain")
140− .overrides_with("number")
144− .help("Show plain style (alias for '--style=plain').")
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').",
@@ -159,49 +158,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
159 '--style=numbers'",
158 '--style=numbers'",
163− Arg::with_name("show-all")
165− .alias("show-nonprintable")
167− .conflicts_with("language")
168− .help("Show non-printable characters (space, tab, newline, ..).")
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."
176− Arg::with_name("line-range")
181− .number_of_values(1)
183− .help("Only print the lines from N to M.")
185− "Only print the specified range of lines for each file. \
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",
193− Arg::with_name("highlight-line")
194− .long("highlight-line")
197− .number_of_values(1)
200− .help("Highlight the given line.")
202− "Highlight the N-th line with a different background color",
206 Arg::with_name("color")
162 Arg::with_name("color")
207 .long("color")
163 .long("color")
@@ -281,39 +237,108 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
284− Arg::with_name("wrap")
240+ Arg::with_name("map-syntax")
285− .long("wrap")
241+ .short("m")
286− .overrides_with("wrap")
242+ .long("map-syntax")
287 .takes_value(true)
244 .takes_value(true)
245+ .number_of_values(1)
288− .value_name("mode")
246+ .value_name("from:to")
289− .possible_values(&["auto", "never", "character"])
247+ .help("Map a file extension or name to an existing syntax.")
290− .default_value("auto")
248+ .long_help(
291− .hide_default_value(true)
249+ "Map a file extension or file name to an existing syntax. For example, \
292− .help("Specify the text-wrapping mode (*auto*, never, character).")
250+ to highlight *.conf files with the INI syntax, use '-m conf:ini'. \
293− .long_help("Specify the text-wrapping mode (*auto*, never, character). \
251+ To highlight files named '.myignore' with the Git Ignore syntax, use \
294− The '--terminal-width' option can be used in addition to \
252+ '-m .myignore:gitignore'.",
295− control the output width."),
253+ )
298− Arg::with_name("tabs")
257+ Arg::with_name("theme")
299− .long("tabs")
258+ .long("theme")
300− .overrides_with("tabs")
259+ .overrides_with("theme")
301 .takes_value(true)
260 .takes_value(true)
261+ .help("Set the color theme for syntax highlighting.")
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=\"...\").",
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."),
277+ Arg::with_name("style")
302− .value_name("T")
279+ .value_name("style-components")
303− .validator(
280+ // Need to turn this off for overrides_with to work as we want. See the bottom most
304− |t| {
281+ // example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
305− t.parse::<u32>()
282+ .use_delimiter(false)
306− .map_err(|_t| "must be a number")
283+ .takes_value(true)
307− .map(|_t| ()) // Convert to Result<(), &str>
284+ .overrides_with("style")
308− .map_err(|e| e.to_string())
285+ .overrides_with("plain")
309− }, // Convert to Result<(), String>
286+ .overrides_with("number")
287+ // Cannot use clap's built in validation because we have to turn off clap's delimiters
289+ let mut invalid_vals = val.split(',').filter(|style| {
291+ "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
296+ if let Some(invalid) = invalid_vals.next() {
297+ Err(format!("Unknown style, '{}'", invalid))
303+ "Comma-separated list of style elements to display \
304+ (*auto*, full, plain, changes, header, grid, numbers, snip).",
311− .help("Set the tab width to T spaces.")
312 .long_help(
306 .long_help(
313− "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
307+ "Configure which elements (line numbers, file headers, grid \
314− directly",
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.",
318+ Arg::with_name("line-range")
323+ .number_of_values(1)
325+ .help("Only print the lines from N to M.")
327+ "Only print the specified range of lines for each file. \
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",
335+ Arg::with_name("list-languages")
336+ .long("list-languages")
338+ .conflicts_with("list-themes")
339+ .help("Display all supported languages.")
340+ .long_help("Display a list of supported languages for syntax highlighting."),
318 Arg::with_name("unbuffered")
343 Arg::with_name("unbuffered")
319 .short("u")
344 .short("u")
@@ -325,31 +350,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
325 is simply ignored.",
350 is simply ignored.",
329− Arg::with_name("terminal-width")
330− .long("terminal-width")
332− .value_name("width")
333− .hidden_short_help(true)
334− .allow_hyphen_values(true)
337− let is_offset = t.starts_with('+') || t.starts_with('-');
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())
345− .map_err(|e| e.to_string())
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'.",
354 Arg::with_name("no-config")
354 Arg::with_name("no-config")
355 .long("no-config")
355 .long("no-config")