on master help sign in
Update options sort order in --help and manpage file

This commit updates the sort order of --help options in order to improve usability/importance putting most useful/used commands on top. In addition to that, similar options were grouped together.

commit3b5fcf461991777fd7bd9f4b89c26d30fc5eb7b3 authorHelder M <heldermartins89@gmail.com> dateWed 23 Oct 2019, 23:25 (7 years ago) parentab2a6ad
2 files changed+240−240
assets/manual/bat.1.in+64−64 src/bin/bat/clap_app.rs+176−176
assets/manual/bat.1.in+64−64
@@ -15,6 +15,17 @@ General remarks
1515Command-line options like '-l'/'--language' that take values can be specified as
1616either '--language value', '--language=value', '-l value' or '-lvalue'.
1717.HP
18+\fB\-A\fR, \fB\-\-show\-all\fR
19+.IP
20+Show non\-printable characters like space, tab or newline. Use '\-\-tabs' to
21+control the width of the tab\-placeholders.
22+.HP
23+\fB\-p\fR, \fB\-\-plain\fR
24+.IP
25+Only show plain style, no decorations. This is an alias for
26+\&'\-\-style=plain'. When '\-p' is used twice ('\-pp'), it also disables
27+automatic paging (alias for '\-\-style=plain \fB\-\-pager\fR=\fI\,never\/\fR').
28+.HP
1829\fB\-l\fR, \fB\-\-language\fR <language>
1930.IP
2031Explicitly set the language for syntax highlighting. The language can be
@@ -22,70 +33,32 @@ specified as a name (like 'C++' or 'LaTeX') or possible file extension
2233(like 'cpp', 'hpp' or 'md'). Use '\-\-list\-languages' to show all supported
2334language names and file extensions.
2435.HP
25−\fB\-L\fR, \fB\-\-list\-languages\fR
26−.IP
27−Display a list of supported languages for syntax highlighting.
28−.HP
29−\fB\-m\fR, \fB\-\-map\-syntax\fR <from:to>...
30−.IP
31−Map a file extension or file name to an existing syntax. For example, to
32−highlight *.conf files with the INI syntax, use '\-m conf:ini'. To
33−highlight files named '.myignore' with the Git Ignore syntax, use '\-m
34−\&.myignore:gitignore'.
35−.HP
36−\fB\-\-theme\fR <theme>
36+\fB\-H\fR, \fB\-\-highlight\-line\fR <N>...
3737.IP
38−Set the theme for syntax highlighting. Use '\-\-list\-themes' to see all
39−available themes. To set a default theme, add the '\-\-theme="..."' option
40−to the configuration file or export the BAT_THEME environment variable
41−(e.g.: export BAT_THEME="...").
38+Highlight the N\-th line with a different background color
4239.HP
43−\fB\-\-list\-themes\fR
40+\fB\-\-tabs\fR <T>
4441.IP
45−Display a list of supported themes for syntax highlighting.
42+Set the tab width to T spaces. Use a width of 0 to pass tabs through
43+directly
4644.HP
47−\fB\-\-style\fR <style\-components>
45+\fB\-\-wrap\fR <mode>
4846.IP
49−Configure which elements (line numbers, file headers, grid borders, Git
50−modifications, ..) to display in addition to the file contents. The
51−argument is a comma\-separated list of components to display (e.g.
52−\&'numbers,changes,grid') or a pre\-defined style ('full'). To set a default
53−style, add the '\-\-style=".."' option to the configuration file or export
54−the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). Possible
55−values: *auto*, full, plain, changes, header, grid, numbers, snip.
47+Specify the text\-wrapping mode (*auto*, never, character). The
48+\&'\-\-terminal\-width' option can be used in addition to control the output
49+width.
5650.HP
57−\fB\-p\fR, \fB\-\-plain\fR
51+\fB\-\-terminal\-width\fR <width>
5852.IP
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 \fB\-\-pager\fR=\fI\,never\/\fR').
53+Explicitly set the width of the terminal instead of determining it
54+automatically. If prefixed with '+' or '\-', the value will be treated as
55+an offset to the actual terminal width. See also: '\-\-wrap'.
6256.HP
6357\fB\-n\fR, \fB\-\-number\fR
6458.IP
6559Only show line numbers, no other decorations. This is an alias for
6660\&'\-\-style=numbers'
6761.HP
68−\fB\-A\fR, \fB\-\-show\-all\fR
69−.IP
70−Show non\-printable characters like space, tab or newline. Use '\-\-tabs' to
71−control the width of the tab\-placeholders.
72−.HP
73−\fB\-r\fR, \fB\-\-line\-range\fR <N:M>...
74−.IP
75−Only print the specified range of lines for each file. For example:
76−.RS
77−.IP "\-\-line\-range 30:40"
78−prints lines 30 to 40
79−.IP "\-\-line\-range :40"
80−prints lines 1 to 40
81−.IP "\-\-line\-range 40:"
82−prints lines 40 to the end of the file
83−.RE
84−.HP
85−\fB\-H\fR, \fB\-\-highlight\-line\fR <N>...
86−.IP
87−Highlight the N\-th line with a different background color
88−.HP
8962\fB\-\-color\fR <when>
9063.IP
9164Specify when to use colored output. The automatic mode only enables colors
@@ -118,28 +91,55 @@ BAT_PAGER environment variables. The default pager is 'less'. To disable
11891the pager completely, use the '\-\-paging' option. Example: '\-\-pager "less
11992\fB\-RF\fR"'.
12093.HP
121−\fB\-\-wrap\fR <mode>
94+\fB\-m\fR, \fB\-\-map\-syntax\fR <from:to>...
12295.IP
123−Specify the text\-wrapping mode (*auto*, never, character). The
124−\&'\-\-terminal\-width' option can be used in addition to control the output
125−width.
96+Map a file extension or file name to an existing syntax. For example, to
97+highlight *.conf files with the INI syntax, use '\-m conf:ini'. To
98+highlight files named '.myignore' with the Git Ignore syntax, use '\-m
99+\&.myignore:gitignore'.
126100.HP
127−\fB\-\-tabs\fR <T>
101+\fB\-\-theme\fR <theme>
128102.IP
129−Set the tab width to T spaces. Use a width of 0 to pass tabs through
130−directly
103+Set the theme for syntax highlighting. Use '\-\-list\-themes' to see all
104+available themes. To set a default theme, add the '\-\-theme="..."' option
105+to the configuration file or export the BAT_THEME environment variable
106+(e.g.: export BAT_THEME="...").
107+.HP
108+\fB\-\-list\-themes\fR
109+.IP
110+Display a list of supported themes for syntax highlighting.
111+.HP
112+\fB\-\-style\fR <style\-components>
113+.IP
114+Configure which elements (line numbers, file headers, grid borders, Git
115+modifications, ..) to display in addition to the file contents. The
116+argument is a comma\-separated list of components to display (e.g.
117+\&'numbers,changes,grid') or a pre\-defined style ('full'). To set a default
118+style, add the '\-\-style=".."' option to the configuration file or export
119+the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). Possible
120+values: *auto*, full, plain, changes, header, grid, numbers, snip.
121+.HP
122+\fB\-r\fR, \fB\-\-line\-range\fR <N:M>...
123+.IP
124+Only print the specified range of lines for each file. For example:
125+.RS
126+.IP "\-\-line\-range 30:40"
127+prints lines 30 to 40
128+.IP "\-\-line\-range :40"
129+prints lines 1 to 40
130+.IP "\-\-line\-range 40:"
131+prints lines 40 to the end of the file
132+.RE
133+.HP
134+\fB\-L\fR, \fB\-\-list\-languages\fR
135+.IP
136+Display a list of supported languages for syntax highlighting.
131137.HP
132138\fB\-u\fR, \fB\-\-unbuffered\fR
133139.IP
134140This option exists for POSIX\-compliance reasons ('u' is for 'unbuffered').
135141The output is always unbuffered \- this option is simply ignored.
136142.HP
137−\fB\-\-terminal\-width\fR <width>
138−.IP
139−Explicitly set the width of the terminal instead of determining it
140−automatically. If prefixed with '+' or '\-', the value will be treated as
141−an offset to the actual terminal width. See also: '\-\-wrap'.
142−.HP
143143\fB\-h\fR, \fB\-\-help\fR
144144.IP
145145Print this help message.
src/bin/bat/clap_app.rs+176−176
@@ -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")