on master help sign in
Generate shell completions with clap during build (#327)

* Generate shell completions with clap during build * Updated ci release script, added SHELL_COMPLETIONS_DIR override to build.rs and fixed dependency version

commit0d7196861523ca14a1df58f7fbf9a75c34723175 authordavideGiovannini <davide.giovannini@studenti.unitn.it> dateWed 3 Oct 2018, 09:39 (8 years ago) parent80da0dc
8 files changed+337−255
Cargo.lock+7 Cargo.toml+4 build.rs+26 ci/before_deploy.bash+6 ci/before_deploy.ps1+1 src/app.rs+3−255 src/clap_app.rs+289 src/main.rs+1
Cargo.lock+7
@@ -109,6 +109,7 @@ dependencies = [
109109 "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
110110 "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
111111 "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
112+ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
112113]
113114
114115[[package]]
@@ -721,6 +722,11 @@ name = "vcpkg"
721722version = "0.2.6"
722723source = "registry+https://github.com/rust-lang/crates.io-index"
723724
725+[[package]]
726+name = "vec_map"
727+version = "0.8.1"
728+source = "registry+https://github.com/rust-lang/crates.io-index"
729+
724730[[package]]
725731name = "version_check"
726732version = "0.1.4"
@@ -883,6 +889,7 @@ dependencies = [
883889"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6"
884890"checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4"
885891"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d"
892+"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
886893"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
887894"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
888895"checksum walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "af464bc7be7b785c7ac72e266a6b67c4c9070155606f51655a650a6686204e35"
Cargo.toml+4
@@ -12,6 +12,7 @@ exclude = [
1212 "assets/syntaxes/*",
1313 "assets/themes/*",
1414]
15+build = "build.rs"
1516
1617[dependencies]
1718atty = "0.2.2"
@@ -43,3 +44,6 @@ features = []
4344
4445[dev-dependencies]
4546tempdir = "0.3"
47+
48+[build-dependencies]
49+clap = "2.32"
build.rsnew file+26
@@ -0,0 +1,26 @@
1+#[macro_use]
2+extern crate clap;
3+
4+use clap::Shell;
5+use std::fs;
6+
7+include!("src/clap_app.rs");
8+
9+const BIN_NAME: &str = "bat";
10+
11+fn main() {
12+ let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
13+
14+ let outdir = match outdir {
15+ None => return,
16+ Some(outdir) => outdir,
17+ };
18+
19+ fs::create_dir_all(&outdir).unwrap();
20+
21+ let mut app = build_app(true);
22+ app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
23+ app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
24+ app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
25+ app.gen_completions(BIN_NAME, Shell::PowerShell, &outdir);
26+}
ci/before_deploy.bash+6
@@ -27,6 +27,7 @@ pack() {
2727
2828 # create a "staging" directory
2929 mkdir "$tempdir/$package_name"
30+ mkdir "$tempdir/$package_name/autocomplete"
3031
3132 # copying the main binary
3233 cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
@@ -38,6 +39,11 @@ pack() {
3839 cp LICENSE-MIT "$tempdir/$package_name"
3940 cp LICENSE-APACHE "$tempdir/$package_name"
4041
42+ # various autocomplete
43+ cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".bash "$tempdir/$package_name/autocomplete/${PROJECT_NAME}.bash-completion"
44+ cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".fish "$tempdir/$package_name/autocomplete"
45+ cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/_"$PROJECT_NAME" "$tempdir/$package_name/autocomplete"
46+
4147 # archiving
4248 pushd "$tempdir"
4349 tar czf "$out_dir/$package_name.tar.gz" "$package_name"/*
ci/before_deploy.ps1+1
@@ -11,6 +11,7 @@ Set-Location $STAGE
1111$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip"
1212
1313Copy-Item "$SRC_DIR\target\release\bat.exe" '.\'
14+Copy-Item $SRC_DIR\target\release\build\bat-*\out\_bat.ps1 '.\'
1415
1516# readme and license
1617Copy-Item $SRC_DIR\README.md '.\'
src/app.rs+3−255
@@ -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> {
src/clap_app.rsnew file+289
@@ -0,0 +1,289 @@
1+use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
2+use std::path::Path;
3+
4+pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
5+ let clap_color_setting = if interactive_output {
6+ AppSettings::ColoredHelp
7+ } else {
8+ AppSettings::ColorNever
9+ };
10+
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();
14+
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)
25+ .max_term_width(90)
26+ .about(
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.",
29+ )
30+ .long_about("A cat(1) clone with syntax highlighting and Git integration.")
31+ .arg(
32+ Arg::with_name("FILE")
33+ .help("File(s) to print / concatenate. Use '-' for standard input.")
34+ .long_help(
35+ "File(s) to print / concatenate. Use a dash ('-') or no argument at all \
36+ to read from standard input.",
37+ )
38+ .multiple(true)
39+ .empty_values(false),
40+ )
41+ .arg(
42+ Arg::with_name("language")
43+ .short("l")
44+ .long("language")
45+ .overrides_with("language")
46+ .help("Set the language for syntax highlighting.")
47+ .long_help(
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.",
52+ )
53+ .takes_value(true),
54+ )
55+ .arg(
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."),
61+ )
62+ .arg(
63+ Arg::with_name("theme")
64+ .long("theme")
65+ .overrides_with("theme")
66+ .takes_value(true)
67+ .help("Set the color theme for syntax highlighting.")
68+ .long_help(
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\").",
73+ ),
74+ )
75+ .arg(
76+ Arg::with_name("list-themes")
77+ .long("list-themes")
78+ .help("Display all supported highlighting themes.")
79+ .long_help("Display a list of supported themes for syntax highlighting."),
80+ )
81+ .arg(
82+ Arg::with_name("style")
83+ .long("style")
84+ .value_name("style-components")
85+ .use_delimiter(true)
86+ .takes_value(true)
87+ .possible_values(&[
88+ "auto", "full", "plain", "changes", "header", "grid", "numbers",
89+ ])
90+ .help("Comma-separated list of style elements to display.")
91+ .long_help(
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\").",
98+ ),
99+ )
100+ .arg(
101+ Arg::with_name("plain")
102+ .overrides_with("plain")
103+ .short("p")
104+ .long("plain")
105+ .conflicts_with("style")
106+ .conflicts_with("number")
107+ .help("Show plain style (alias for '--style=plain').")
108+ .long_help(
109+ "Only show plain style, no decorations. This is an alias for \
110+ '--style=plain'",
111+ ),
112+ )
113+ .arg(
114+ Arg::with_name("number")
115+ .long("number")
116+ .overrides_with("number")
117+ .short("n")
118+ .conflicts_with("style")
119+ .help("Show line numbers (alias for '--style=numbers').")
120+ .long_help(
121+ "Only show line numbers, no other decorations. This is an alias for \
122+ '--style=numbers'",
123+ ),
124+ )
125+ .arg(
126+ Arg::with_name("line-range")
127+ .long("line-range")
128+ .overrides_with("line-range")
129+ .takes_value(true)
130+ .value_name("N:M")
131+ .help("Only print the lines from N to M.")
132+ .long_help(
133+ "Only print the specified range of lines for each file. \
134+ For example:\n \
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",
138+ ),
139+ )
140+ .arg(
141+ Arg::with_name("color")
142+ .long("color")
143+ .overrides_with("color")
144+ .takes_value(true)
145+ .value_name("when")
146+ .possible_values(&["auto", "never", "always"])
147+ .default_value("auto")
148+ .help("When to use colors.")
149+ .long_help(
150+ "Specify when to use colored output. The automatic mode \
151+ only enables colors if an interactive terminal is detected.",
152+ ),
153+ )
154+ .arg(
155+ Arg::with_name("decorations")
156+ .long("decorations")
157+ .overrides_with("decorations")
158+ .takes_value(true)
159+ .value_name("when")
160+ .possible_values(&["auto", "never", "always"])
161+ .default_value("auto")
162+ .help("When to show the decorations specified by '--style'.")
163+ .long_help(
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.",
167+ ),
168+ )
169+ .arg(
170+ Arg::with_name("paging")
171+ .long("paging")
172+ .overrides_with("paging")
173+ .takes_value(true)
174+ .value_name("when")
175+ .possible_values(&["auto", "never", "always"])
176+ .default_value("auto")
177+ .help("Specify when to use the pager.")
178+ .long_help(
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.",
184+ ),
185+ )
186+ .arg(
187+ Arg::with_name("wrap")
188+ .long("wrap")
189+ .overrides_with("wrap")
190+ .takes_value(true)
191+ .value_name("mode")
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."),
196+ )
197+ .arg(
198+ Arg::with_name("unbuffered")
199+ .short("u")
200+ .hidden_short_help(true)
201+ .long_help(
202+ "This option exists for POSIX-compliance reasons ('u' is for \
203+ 'unbuffered'). The output is always unbuffered - this option \
204+ is simply ignored.",
205+ ),
206+ )
207+ .arg(
208+ Arg::with_name("tabs")
209+ .long("tabs")
210+ .takes_value(true)
211+ .value_name("tabs")
212+ .validator(
213+ |t| {
214+ t.parse::<u32>()
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>
219+ )
220+ .help("Sets the tab width.")
221+ .long_help(
222+ "Sets the tab width. Use a width of 0 to pass tabs through \
223+ directly",
224+ ),
225+ )
226+ .arg(
227+ Arg::with_name("terminal-width")
228+ .long("terminal-width")
229+ .takes_value(true)
230+ .value_name("width")
231+ .hidden(true)
232+ .help("Set the width of the terminal"),
233+ )
234+ .subcommand(
235+ SubCommand::with_name("cache")
236+ .about("Modify the syntax-definition and theme cache")
237+ .arg(
238+ Arg::with_name("init")
239+ .long("init")
240+ .short("i")
241+ .help("Initialize the syntax/theme cache.")
242+ .long_help(
243+ "Initialize the syntax/theme cache by loading from the \
244+ source directory (default: the configuration directory).",
245+ ),
246+ )
247+ .arg(
248+ Arg::with_name("clear")
249+ .long("clear")
250+ .short("c")
251+ .help("Remove the cached syntax definitions and themes."),
252+ )
253+ .arg(
254+ Arg::with_name("config-dir")
255+ .long("config-dir")
256+ .short("d")
257+ .help("Show bat's configuration directory."),
258+ )
259+ .group(
260+ ArgGroup::with_name("cache-actions")
261+ .args(&["init", "clear", "config-dir"])
262+ .required(arg_group_required),
263+ )
264+ .arg(
265+ Arg::with_name("source")
266+ .long("source")
267+ .requires("init")
268+ .takes_value(true)
269+ .value_name("dir")
270+ .help("Use a different directory to load syntaxes and themes from."),
271+ )
272+ .arg(
273+ Arg::with_name("target")
274+ .long("target")
275+ .requires("init")
276+ .takes_value(true)
277+ .value_name("dir")
278+ .help(
279+ "Use a different directory to store the cached syntax and theme set.",
280+ ),
281+ )
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).",
285+ )),
286+ )
287+ .help_message("Print this help message.")
288+ .version_message("Show version information.")
289+}
src/main.rs+1
@@ -19,6 +19,7 @@ extern crate syntect;
1919
2020mod app;
2121mod assets;
22+mod clap_app;
2223mod controller;
2324mod decorations;
2425mod diff;