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::NextLineHelp)
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("theme")
65 .overrides_with("theme")
67 .help("Set the color theme for syntax highlighting.")
69 "Set the theme for syntax highlighting. Use '--list-themes' to \
70 see all available themes. To set a default theme, export the \
71 BAT_THEME environment variable (e.g.: export \
72 BAT_THEME=\"TwoDark\").",
76 Arg::with_name("list-themes")
78 .help("Display all supported highlighting themes.")
79 .long_help("Display a list of supported themes for syntax highlighting."),
82 Arg::with_name("style")
84 .value_name("style-components")
88 "auto", "full", "plain", "changes", "header", "grid", "numbers",
90 .help("Comma-separated list of style elements to display.")
92 "Configure which elements (line numbers, file headers, grid \
93 borders, Git modifications, ..) to display in addition to the \
94 file contents. The argument is a comma-separated list of \
95 components to display (e.g. 'numbers,changes,grid') or a \
96 pre-defined style ('full'). To set a default theme, export the \
97 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
101 Arg::with_name("plain")
102 .overrides_with("plain")
105 .conflicts_with("style")
106 .conflicts_with("number")
107 .help("Show plain style (alias for '--style=plain').")
109 "Only show plain style, no decorations. This is an alias for \
114 Arg::with_name("number")
116 .overrides_with("number")
118 .conflicts_with("style")
119 .help("Show line numbers (alias for '--style=numbers').")
121 "Only show line numbers, no other decorations. This is an alias for \
126 Arg::with_name("line-range")
128 .overrides_with("line-range")
131 .help("Only print the lines from N to M.")
133 "Only print the specified range of lines for each file. \
135 '--line-range 30:40' prints lines 30 to 40\n \
136 '--line-range :40' prints lines 1 to 40\n \
137 '--line-range 40:' prints lines 40 to the end of the file",
141 Arg::with_name("color")
143 .overrides_with("color")
146 .possible_values(&["auto", "never", "always"])
147 .default_value("auto")
148 .help("When to use colors.")
150 "Specify when to use colored output. The automatic mode \
151 only enables colors if an interactive terminal is detected.",
155 Arg::with_name("decorations")
157 .overrides_with("decorations")
160 .possible_values(&["auto", "never", "always"])
161 .default_value("auto")
162 .help("When to show the decorations specified by '--style'.")
164 "Specify when to use the decorations that have been specified \
165 via '--style'. The automatic mode only enables decorations if \
166 an interactive terminal is detected.",
170 Arg::with_name("paging")
172 .overrides_with("paging")
175 .possible_values(&["auto", "never", "always"])
176 .default_value("auto")
177 .help("Specify when to use the pager.")
179 "Specify when to use the pager. To control which pager \
180 is used, set the PAGER or BAT_PAGER environment \
181 variables (the latter takes precedence). The default \
182 pager is 'less'. To disable the pager permanently, set \
183 BAT_PAGER to an empty string.",
187 Arg::with_name("wrap")
189 .overrides_with("wrap")
192 .possible_values(&["auto", "never", "character"])
193 .default_value("auto")
194 .help("Specify the text-wrapping mode.")
195 .long_help("Specify the text-wrapping mode."),
198 Arg::with_name("unbuffered")
200 .hidden_short_help(true)
202 "This option exists for POSIX-compliance reasons ('u' is for \
203 'unbuffered'). The output is always unbuffered - this option \
208 Arg::with_name("tabs")
215 .map_err(|_t| "must be a number")
216 .map(|_t| ()) // Convert to Result<(), &str>
217 .map_err(|e| e.to_string())
218 }, // Convert to Result<(), String>
220 .help("Sets the tab width.")
222 "Sets the tab width. Use a width of 0 to pass tabs through \
227 Arg::with_name("terminal-width")
228 .long("terminal-width")
232 .help("Set the width of the terminal"),
235 SubCommand::with_name("cache")
236 .about("Modify the syntax-definition and theme cache")
238 Arg::with_name("init")
241 .help("Initialize the syntax/theme cache.")
243 "Initialize the syntax/theme cache by loading from the \
244 source directory (default: the configuration directory).",
248 Arg::with_name("clear")
251 .help("Remove the cached syntax definitions and themes."),
254 Arg::with_name("config-dir")
257 .help("Show bat's configuration directory."),
260 ArgGroup::with_name("cache-actions")
261 .args(&["init", "clear", "config-dir"])
262 .required(arg_group_required),
265 Arg::with_name("source")
270 .help("Use a different directory to load syntaxes and themes from."),
273 Arg::with_name("target")
279 "Use a different directory to store the cached syntax and theme set.",
282 .arg(Arg::with_name("blank").long("blank").requires("init").help(
283 "Create completely new syntax and theme sets \
284 (instead of appending to the default sets).",
287 .help_message("Print this help message.")
288 .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