@@ -1,11 +1,11 @@
11use std::collections::HashSet;
22use std::env;
3−use std::path::Path;
43use std::str::FromStr;
54
65use atty::{self, Stream};
76
8−use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
7+use clap::ArgMatches;
8+use clap_app;
99
1010use console::Term;
1111
@@ -102,259 +102,7 @@ impl App {
102102 }
103103
104104 fn matches(interactive_output: bool) -> ArgMatches<'static> {
105− let clap_color_setting = if interactive_output {
106− AppSettings::ColoredHelp
107− } else {
108− AppSettings::ColorNever
109− };
110−
111− // Check if the current directory contains a file name cache, if it does
112− // do not make the arguements for subcommand 'cache' required.
113− let arg_group_required = !Path::new("cache").exists();
114−
115− ClapApp::new(crate_name!())
116− .version(crate_version!())
117− .global_setting(clap_color_setting)
118− .global_setting(AppSettings::DeriveDisplayOrder)
119− .global_setting(AppSettings::UnifiedHelpMessage)
120− .global_setting(AppSettings::NextLineHelp)
121− .setting(AppSettings::InferSubcommands)
122− .setting(AppSettings::ArgsNegateSubcommands)
123− .setting(AppSettings::DisableHelpSubcommand)
124− .setting(AppSettings::VersionlessSubcommands)
125− .max_term_width(90)
126− .about(
127− "A cat(1) clone with wings.\n\n\
128− Use '--help' instead of '-h' to see a more detailed version of the help text.",
129− ).long_about("A cat(1) clone with syntax highlighting and Git integration.")
130− .arg(
131− Arg::with_name("FILE")
132− .help("File(s) to print / concatenate. Use '-' for standard input.")
133− .long_help(
134− "File(s) to print / concatenate. Use a dash ('-') or no argument at all \
135− to read from standard input.",
136− ).multiple(true)
137− .empty_values(false),
138− )
139− .arg(
140− Arg::with_name("language")
141− .short("l")
142− .long("language")
143− .overrides_with("language")
144− .help("Set the language for syntax highlighting.")
145− .long_help(
146− "Explicitly set the language for syntax highlighting. The language can be \
147− specified as a name (like 'C++' or 'LaTeX') or possible file extension \
148− (like 'cpp', 'hpp' or 'md'). Use '--list-languages' to show all supported \
149− language names and file extensions."
150− ).takes_value(true),
151− ).arg(
152− Arg::with_name("list-languages")
153− .long("list-languages")
154− .conflicts_with("list-themes")
155− .help("Display all supported languages.")
156− .long_help("Display a list of supported languages for syntax highlighting."),
157− ).arg(
158− Arg::with_name("theme")
159− .long("theme")
160− .overrides_with("theme")
161− .takes_value(true)
162− .help("Set the color theme for syntax highlighting.")
163− .long_help(
164− "Set the theme for syntax highlighting. Use '--list-themes' to \
165− see all available themes. To set a default theme, export the \
166− BAT_THEME environment variable (e.g.: export \
167− BAT_THEME=\"TwoDark\").",
168− ),
169− ).arg(
170− Arg::with_name("list-themes")
171− .long("list-themes")
172− .help("Display all supported highlighting themes.")
173− .long_help("Display a list of supported themes for syntax highlighting."),
174− ).arg(
175− Arg::with_name("style")
176− .long("style")
177− .value_name("style-components")
178− .use_delimiter(true)
179− .takes_value(true)
180− .possible_values(&[
181− "auto", "full", "plain", "changes", "header", "grid", "numbers",
182− ])
183− .help("Comma-separated list of style elements to display.")
184− .long_help(
185− "Configure which elements (line numbers, file headers, grid \
186− borders, Git modifications, ..) to display in addition to the \
187− file contents. The argument is a comma-separated list of \
188− components to display (e.g. 'numbers,changes,grid') or a \
189− pre-defined style ('full'). To set a default theme, export the \
190− BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
191− ),
192− ).arg(
193− Arg::with_name("plain")
194− .overrides_with("plain")
195− .short("p")
196− .long("plain")
197− .conflicts_with("style")
198− .conflicts_with("number")
199− .help("Show plain style (alias for '--style=plain').")
200− .long_help(
201− "Only show plain style, no decorations. This is an alias for \
202− '--style=plain'",
203− ),
204− ).arg(
205− Arg::with_name("number")
206− .long("number")
207− .overrides_with("number")
208− .short("n")
209− .conflicts_with("style")
210− .help("Show line numbers (alias for '--style=numbers').")
211− .long_help(
212− "Only show line numbers, no other decorations. This is an alias for \
213− '--style=numbers'",
214− ),
215− ).arg(
216− Arg::with_name("line-range")
217− .long("line-range")
218− .overrides_with("line-range")
219− .takes_value(true)
220− .value_name("N:M")
221− .help("Only print the lines from N to M.")
222− .long_help(
223− "Only print the specified range of lines for each file. \
224− For example:\n \
225− '--line-range 30:40' prints lines 30 to 40\n \
226− '--line-range :40' prints lines 1 to 40\n \
227− '--line-range 40:' prints lines 40 to the end of the file",
228− ),
229− ).arg(
230− Arg::with_name("color")
231− .long("color")
232− .overrides_with("color")
233− .takes_value(true)
234− .value_name("when")
235− .possible_values(&["auto", "never", "always"])
236− .default_value("auto")
237− .help("When to use colors.")
238− .long_help("Specify when to use colored output. The automatic mode \
239− only enables colors if an interactive terminal is detected."),
240− ).arg(
241− Arg::with_name("decorations")
242− .long("decorations")
243− .overrides_with("decorations")
244− .takes_value(true)
245− .value_name("when")
246− .possible_values(&["auto", "never", "always"])
247− .default_value("auto")
248− .help("When to show the decorations specified by '--style'.")
249− .long_help("Specify when to use the decorations that have been specified \
250− via '--style'. The automatic mode only enables decorations if \
251− an interactive terminal is detected."),
252− ).arg(
253− Arg::with_name("paging")
254− .long("paging")
255− .overrides_with("paging")
256− .takes_value(true)
257− .value_name("when")
258− .possible_values(&["auto", "never", "always"])
259− .default_value("auto")
260− .help("Specify when to use the pager.")
261− .long_help("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). The default \
264− pager is 'less'. To disable the pager permanently, set \
265− BAT_PAGER to an empty string."),
266− ).arg(
267− Arg::with_name("wrap")
268− .long("wrap")
269− .overrides_with("wrap")
270− .takes_value(true)
271− .value_name("mode")
272− .possible_values(&["auto", "never", "character"])
273− .default_value("auto")
274− .help("Specify the text-wrapping mode.")
275− .long_help("Specify the text-wrapping mode."),
276− ).arg(
277− Arg::with_name("unbuffered")
278− .short("u")
279− .hidden_short_help(true)
280− .long_help(
281− "This option exists for POSIX-compliance reasons ('u' is for \
282− 'unbuffered'). The output is always unbuffered - this option \
283− is simply ignored.",
284− ),
285− ).arg(
286− Arg::with_name("tabs")
287− .long("tabs")
288− .takes_value(true)
289− .value_name("tabs")
290− .validator(
291− |t| t.parse::<u32>()
292− .map_err(|_t| "must be a number")
293− .map(|_t| ()) // Convert to Result<(), &str>
294− .map_err(|e| e.to_string()) // Convert to Result<(), String>
295− )
296− .help("Sets the tab width.")
297− .long_help("Sets the tab width. Use a width of 0 to pass tabs through \
298− directly"),
299− ).arg(
300− Arg::with_name("terminal-width")
301− .long("terminal-width")
302− .takes_value(true)
303− .value_name("width")
304− .hidden(true)
305− .help("Set the width of the terminal"),
306− ).subcommand(
307− SubCommand::with_name("cache")
308− .about("Modify the syntax-definition and theme cache")
309− .arg(
310− Arg::with_name("init")
311− .long("init")
312− .short("i")
313− .help("Initialize the syntax/theme cache.")
314− .long_help(
315− "Initialize the syntax/theme cache by loading from the \
316− source directory (default: the configuration directory).",
317− ),
318− ).arg(
319− Arg::with_name("clear")
320− .long("clear")
321− .short("c")
322− .help("Remove the cached syntax definitions and themes."),
323− ).arg(
324− Arg::with_name("config-dir")
325− .long("config-dir")
326− .short("d")
327− .help("Show bat's configuration directory."),
328− ).group(
329− ArgGroup::with_name("cache-actions")
330− .args(&["init", "clear", "config-dir"])
331− .required(arg_group_required),
332− ).arg(
333− Arg::with_name("source")
334− .long("source")
335− .requires("init")
336− .takes_value(true)
337− .value_name("dir")
338− .help("Use a different directory to load syntaxes and themes from."),
339− ).arg(
340− Arg::with_name("target")
341− .long("target")
342− .requires("init")
343− .takes_value(true)
344− .value_name("dir")
345− .help(
346− "Use a different directory to store the cached syntax and theme set.",
347− ),
348− ).arg(
349− Arg::with_name("blank")
350− .long("blank")
351− .requires("init")
352− .help("Create completely new syntax and theme sets \
353− (instead of appending to the default sets).")
354− ),
355− ).help_message("Print this help message.")
356− .version_message("Show version information.")
357− .get_matches()
105+ clap_app::build_app(interactive_output).get_matches()
358106 }
359107
360108 pub fn config(&self) -> Result<Config> {