1use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
4pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
5 let clap_color_setting = if interactive_output {
6 AppSettings::ColoredHelp
8 AppSettings::ColorNever
11 // Check if the current directory contains a file name cache, if it does
12 // do not make the arguements for subcommand 'cache' required.
13 let arg_group_required = !Path::new("cache").exists();
15 ClapApp::new(crate_name!())
16 .version(crate_version!())
17 .global_setting(clap_color_setting)
18 .global_setting(AppSettings::DeriveDisplayOrder)
19 .global_setting(AppSettings::UnifiedHelpMessage)
20 .global_setting(AppSettings::HidePossibleValuesInHelp)
21 .setting(AppSettings::InferSubcommands)
22 .setting(AppSettings::ArgsNegateSubcommands)
23 .setting(AppSettings::DisableHelpSubcommand)
24 .setting(AppSettings::VersionlessSubcommands)
27 "A cat(1) clone with wings.\n\n\
28 Use '--help' instead of '-h' to see a more detailed version of the help text.",
30 .long_about("A cat(1) clone with syntax highlighting and Git integration.")
32 Arg::with_name("FILE")
33 .help("File(s) to print / concatenate. Use '-' for standard input.")
35 "File(s) to print / concatenate. Use a dash ('-') or no argument at all \
36 to read from standard input.",
42 Arg::with_name("language")
45 .overrides_with("language")
46 .help("Set the language for syntax highlighting.")
48 "Explicitly set the language for syntax highlighting. The language can be \
49 specified as a name (like 'C++' or 'LaTeX') or possible file extension \
50 (like 'cpp', 'hpp' or 'md'). Use '--list-languages' to show all supported \
51 language names and file extensions.",
56 Arg::with_name("list-languages")
57 .long("list-languages")
58 .conflicts_with("list-themes")
59 .help("Display all supported languages.")
60 .long_help("Display a list of supported languages for syntax highlighting."),
63 Arg::with_name("map-syntax")
69 .value_name("from:to")
70 .help("Map a file extension or name to an existing syntax.")
72 "Map a file extension or file name to an existing syntax. For example, \
73 to highlight *.conf files with the INI syntax, use '-m conf:ini'. \
74 To highlight files named '.myignore' with the Git Ignore syntax, use \
75 '-m .myignore:gitignore'.",
80 Arg::with_name("theme")
82 .overrides_with("theme")
84 .help("Set the color theme for syntax highlighting.")
86 "Set the theme for syntax highlighting. Use '--list-themes' to \
87 see all available themes. To set a default theme, add the \
88 '--theme=\"...\"' option to the configuration file or export the \
89 BAT_THEME environment variable (e.g.: export \
94 Arg::with_name("list-themes")
96 .help("Display all supported highlighting themes.")
97 .long_help("Display a list of supported themes for syntax highlighting."),
100 Arg::with_name("style")
102 .value_name("style-components")
103 // Need to turn this off for overrides_with to work as we want. See the bottom most
104 // example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
105 .use_delimiter(false)
107 .overrides_with("style")
108 .overrides_with("plain")
109 .overrides_with("number")
110 // Cannot use clap's built in validation because we have to turn off clap's delimiters
112 let mut invalid_vals = val.split(',').filter(|style| {
114 "auto", "full", "plain", "changes", "header", "grid", "numbers",
119 if let Some(invalid) = invalid_vals.next() {
120 Err(format!("Unknown style, '{}'", invalid))
126 "Comma-separated list of style elements to display \
127 (*auto*, full, plain, changes, header, grid, numbers).",
130 "Configure which elements (line numbers, file headers, grid \
131 borders, Git modifications, ..) to display in addition to the \
132 file contents. The argument is a comma-separated list of \
133 components to display (e.g. 'numbers,changes,grid') or a \
134 pre-defined style ('full'). To set a default style, add the \
135 '--style=\"..\"' option to the configuration file or export the \
136 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\"). \
137 Possible values: *auto*, full, plain, changes, header, grid, numbers.",
141 Arg::with_name("plain")
142 .overrides_with("plain")
143 .overrides_with("number")
147 .help("Show plain style (alias for '--style=plain').")
149 "Only show plain style, no decorations. This is an alias for \
150 '--style=plain'. When '-p' is used twice ('-pp'), it also disables \
151 automatic paging (alias for '--style=plain --pager=never').",
155 Arg::with_name("number")
157 .overrides_with("number")
159 .help("Show line numbers (alias for '--style=numbers').")
161 "Only show line numbers, no other decorations. This is an alias for \
166 Arg::with_name("show-all")
168 .alias("show-nonprintable")
170 .conflicts_with("language")
171 .help("Show non-printable characters (space, tab, newline, ..).")
173 "Show non-printable characters like space, tab or newline. \
174 Use '--tabs' to control the width of the tab-placeholders.",
178 Arg::with_name("line-range")
185 .help("Only print the lines from N to M.")
187 "Only print the specified range of lines for each file. \
189 '--line-range 30:40' prints lines 30 to 40\n \
190 '--line-range :40' prints lines 1 to 40\n \
191 '--line-range 40:' prints lines 40 to the end of the file",
195 Arg::with_name("highlight-line")
196 .long("highlight-line")
202 .help("Highlight the given line.")
204 "Highlight the N-th line with a different background color",
208 Arg::with_name("color")
210 .overrides_with("color")
213 .possible_values(&["auto", "never", "always"])
214 .hide_default_value(true)
215 .default_value("auto")
216 .help("When to use colors (*auto*, never, always).")
218 "Specify when to use colored output. The automatic mode \
219 only enables colors if an interactive terminal is detected. \
220 Possible values: *auto*, never, always.",
224 Arg::with_name("italic-text")
228 .possible_values(&["always", "never"])
229 .default_value("never")
230 .hide_default_value(true)
231 .help("Use italics in output (always, *never*)")
232 .long_help("Specify when to use ANSI sequences for italic text in the output. Possible values: always, *never*."),
235 Arg::with_name("decorations")
237 .overrides_with("decorations")
240 .possible_values(&["auto", "never", "always"])
241 .default_value("auto")
242 .hide_default_value(true)
243 .help("When to show the decorations (*auto*, never, always).")
245 "Specify when to use the decorations that have been specified \
246 via '--style'. The automatic mode only enables decorations if \
247 an interactive terminal is detected. Possible values: *auto*, never, always.",
251 Arg::with_name("paging")
253 .overrides_with("paging")
256 .possible_values(&["auto", "never", "always"])
257 .default_value("auto")
258 .hide_default_value(true)
259 .help("Specify when to use the pager (*auto*, never, always).")
261 "Specify when to use the pager. To control which pager \
262 is used, set the PAGER or BAT_PAGER environment \
263 variables (the latter takes precedence) or use the '--pager' option. \
264 To disable the pager permanently, set BAT_PAGER to an empty string \
265 or set '--paging=never' in the configuration file. \
266 Possible values: *auto*, never, always.",
270 Arg::with_name("pager")
272 .overrides_with("pager")
274 .value_name("command")
275 .hidden_short_help(true)
276 .help("Determine which pager to use.")
278 "Determine which pager is used. This option will overwrite \
279 the PAGER and BAT_PAGER environment variables. The default \
280 pager is 'less'. To disable the pager completely, use the \
282 Example: '--pager \"less -RF\"'.",
286 Arg::with_name("wrap")
288 .overrides_with("wrap")
291 .possible_values(&["auto", "never", "character"])
292 .default_value("auto")
293 .hide_default_value(true)
294 .help("Specify the text-wrapping mode (*auto*, never, character).")
295 .long_help("Specify the text-wrapping mode (*auto*, never, character)."),
298 Arg::with_name("tabs")
300 .overrides_with("tabs")
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>
311 .help("Set the tab width to T spaces.")
313 "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
318 Arg::with_name("unbuffered")
321 .hidden_short_help(true)
323 "This option exists for POSIX-compliance reasons ('u' is for \
324 'unbuffered'). The output is always unbuffered - this option \
329 Arg::with_name("terminal-width")
330 .long("terminal-width")
333 .hidden_short_help(true)
336 let is_offset = t.starts_with('+') || t.starts_with('-');
337 let num = if is_offset {
338 t.chars().skip(1).collect()
344 .map_err(|_e| "must be an offset or number")
345 .and_then(|v| if v == 0 && !is_offset {
346 Err("terminal width cannot be zero".into())
350 .map_err(|e| e.to_string())
353 "Explicitly set the width of the terminal instead of determining it \
354 automatically. If prefixed with '+' or '-', the value will be treated \
355 as an offset to the actual terminal width.",
359 Arg::with_name("no-config")
362 .help("Do not use the configuration file"),
365 Arg::with_name("config-file")
367 .conflicts_with("list-languages")
368 .conflicts_with("list-themes")
370 .help("Show path to the configuration file."),
373 Arg::with_name("config-dir")
376 .help("Show bat's configuration directory."),
379 Arg::with_name("cache-dir")
382 .help("Show bat's cache directory."),
385 SubCommand::with_name("cache")
386 .about("Modify the syntax-definition and theme cache")
388 Arg::with_name("build")
391 .help("Initialize (or update) the syntax/theme cache.")
393 "Initialize (or update) the syntax/theme cache by loading from \
394 the source directory (default: the configuration directory).",
398 Arg::with_name("clear")
401 .help("Remove the cached syntax definitions and themes."),
404 ArgGroup::with_name("cache-actions")
405 .args(&["build", "clear"])
406 .required(arg_group_required),
409 Arg::with_name("source")
414 .help("Use a different directory to load syntaxes and themes from."),
417 Arg::with_name("target")
423 "Use a different directory to store the cached syntax and theme set.",
426 .arg(Arg::with_name("blank").long("blank").requires("build").help(
427 "Create completely new syntax and theme sets \
428 (instead of appending to the default sets).",
431 .help_message("Print this help message.")
432 .version_message("Show version information.")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list