2022-09-02 02:03:25 +02:00
|
|
|
use clap::{
|
2022-09-02 03:35:49 +02:00
|
|
|
crate_name, crate_version, value_parser, AppSettings, Arg, ArgAction, ArgGroup, ColorChoice,
|
|
|
|
Command,
|
2022-09-02 02:03:25 +02:00
|
|
|
};
|
2021-11-22 21:10:17 +01:00
|
|
|
use once_cell::sync::Lazy;
|
2020-05-28 01:38:43 +02:00
|
|
|
use std::env;
|
2022-09-02 02:03:25 +02:00
|
|
|
use std::path::{Path, PathBuf};
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2021-11-22 21:10:17 +01:00
|
|
|
static VERSION: Lazy<String> = Lazy::new(|| {
|
|
|
|
#[cfg(feature = "bugreport")]
|
|
|
|
let git_version = bugreport::git_version!(fallback = "");
|
|
|
|
#[cfg(not(feature = "bugreport"))]
|
|
|
|
let git_version = "";
|
2021-10-23 16:32:39 +02:00
|
|
|
|
2021-11-22 21:10:17 +01:00
|
|
|
if git_version.is_empty() {
|
|
|
|
crate_version!().to_string()
|
|
|
|
} else {
|
|
|
|
format!("{} ({})", crate_version!(), git_version)
|
|
|
|
}
|
|
|
|
});
|
2021-10-23 16:32:39 +02:00
|
|
|
|
2022-09-02 02:03:25 +02:00
|
|
|
pub fn build_app(interactive_output: bool) -> Command<'static> {
|
|
|
|
let color_when = if interactive_output && env::var_os("NO_COLOR").is_none() {
|
|
|
|
ColorChoice::Auto
|
2018-10-03 09:39:30 +02:00
|
|
|
} else {
|
2022-09-02 02:03:25 +02:00
|
|
|
ColorChoice::Never
|
2018-10-03 09:39:30 +02:00
|
|
|
};
|
|
|
|
|
2022-09-02 02:03:25 +02:00
|
|
|
let mut app = Command::new(crate_name!())
|
2021-10-23 16:32:39 +02:00
|
|
|
.version(VERSION.as_str())
|
2022-09-02 02:03:25 +02:00
|
|
|
.color(color_when)
|
2018-10-03 09:39:30 +02:00
|
|
|
.global_setting(AppSettings::DeriveDisplayOrder)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_possible_values(true)
|
|
|
|
.args_conflicts_with_subcommands(true)
|
|
|
|
.allow_external_subcommands(true)
|
|
|
|
.disable_help_subcommand(true)
|
2018-10-07 10:43:39 +02:00
|
|
|
.max_term_width(100)
|
2018-10-03 09:39:30 +02:00
|
|
|
.about(
|
|
|
|
"A cat(1) clone with wings.\n\n\
|
|
|
|
Use '--help' instead of '-h' to see a more detailed version of the help text.",
|
|
|
|
)
|
2020-10-03 20:50:17 +02:00
|
|
|
.after_help(
|
|
|
|
"Note: `bat -h` prints a short and concise overview while `bat --help` gives all \
|
|
|
|
details.",
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.long_about("A cat(1) clone with syntax highlighting and Git integration.")
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("FILE")
|
2018-10-03 09:39:30 +02:00
|
|
|
.help("File(s) to print / concatenate. Use '-' for standard input.")
|
|
|
|
.long_help(
|
|
|
|
"File(s) to print / concatenate. Use a dash ('-') or no argument at all \
|
|
|
|
to read from standard input.",
|
|
|
|
)
|
2022-09-01 22:41:07 +02:00
|
|
|
.takes_value(true)
|
2022-09-02 02:03:25 +02:00
|
|
|
.multiple_values(true)
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(value_parser!(PathBuf)),
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
2019-10-24 00:25:02 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("show-all")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("show-all")
|
|
|
|
.alias("show-nonprintable")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('A')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2019-10-24 00:25:02 +02:00
|
|
|
.conflicts_with("language")
|
|
|
|
.help("Show non-printable characters (space, tab, newline, ..).")
|
|
|
|
.long_help(
|
|
|
|
"Show non-printable characters like space, tab or newline. \
|
|
|
|
This option can also be used to print binary files. \
|
2020-05-13 07:24:51 +02:00
|
|
|
Use '--tabs' to control the width of the tab-placeholders.",
|
2019-10-24 00:25:02 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("plain")
|
2019-10-24 00:25:02 +02:00
|
|
|
.overrides_with("plain")
|
|
|
|
.overrides_with("number")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('p')
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("plain")
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Count)
|
2019-10-24 00:25:02 +02:00
|
|
|
.help("Show plain style (alias for '--style=plain').")
|
|
|
|
.long_help(
|
|
|
|
"Only show plain style, no decorations. This is an alias for \
|
|
|
|
'--style=plain'. When '-p' is used twice ('-pp'), it also disables \
|
2022-07-06 07:48:53 +02:00
|
|
|
automatic paging (alias for '--style=plain --paging=never').",
|
2019-10-24 00:25:02 +02:00
|
|
|
),
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("language")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('l')
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("language")
|
|
|
|
.overrides_with("language")
|
|
|
|
.help("Set the language for syntax highlighting.")
|
|
|
|
.long_help(
|
|
|
|
"Explicitly set the language for syntax highlighting. The language can be \
|
|
|
|
specified as a name (like 'C++' or 'LaTeX') or possible file extension \
|
|
|
|
(like 'cpp', 'hpp' or 'md'). Use '--list-languages' to show all supported \
|
|
|
|
language names and file extensions.",
|
|
|
|
)
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("highlight-line")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("highlight-line")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('H')
|
2018-10-17 22:30:09 +02:00
|
|
|
.takes_value(true)
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Append)
|
2020-01-23 04:26:21 +01:00
|
|
|
.value_name("N:M")
|
|
|
|
.help("Highlight lines N through M.")
|
2018-10-17 22:30:09 +02:00
|
|
|
.long_help(
|
2020-01-23 04:26:21 +01:00
|
|
|
"Highlight the specified line ranges with a different background color \
|
|
|
|
For example:\n \
|
2020-01-27 01:19:54 +01:00
|
|
|
'--highlight-line 40' highlights line 40\n \
|
2020-01-23 04:26:21 +01:00
|
|
|
'--highlight-line 30:40' highlights lines 30 to 40\n \
|
|
|
|
'--highlight-line :40' highlights lines 1 to 40\n \
|
2021-08-21 19:55:52 +02:00
|
|
|
'--highlight-line 40:' highlights lines 40 to the end of the file\n \
|
|
|
|
'--highlight-line 30:+10' highlights lines 30 to 40",
|
2019-10-24 00:25:02 +02:00
|
|
|
),
|
2018-10-17 22:30:09 +02:00
|
|
|
)
|
2020-03-18 03:24:48 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("file-name")
|
2020-03-18 03:24:48 +01:00
|
|
|
.long("file-name")
|
|
|
|
.takes_value(true)
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Append)
|
2020-03-18 03:24:48 +01:00
|
|
|
.value_name("name")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(value_parser!(PathBuf))
|
2020-03-18 03:24:48 +01:00
|
|
|
.help("Specify the name to display for a file.")
|
2020-04-23 23:39:30 +02:00
|
|
|
.long_help(
|
2020-05-13 07:24:51 +02:00
|
|
|
"Specify the name to display for a file. Useful when piping \
|
2020-09-20 20:47:21 +02:00
|
|
|
data to bat from STDIN when bat does not otherwise know \
|
|
|
|
the filename. Note that the provided file name is also \
|
|
|
|
used for syntax detection.",
|
2020-04-23 23:39:30 +02:00
|
|
|
),
|
2020-05-13 07:24:51 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
{
|
|
|
|
app = app
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("diff")
|
2020-05-13 07:24:51 +02:00
|
|
|
.long("diff")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('d')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-01 22:41:07 +02:00
|
|
|
.conflicts_with("line-range")
|
2020-05-13 07:24:51 +02:00
|
|
|
.help("Only show lines that have been added/removed/modified.")
|
|
|
|
.long_help(
|
|
|
|
"Only show lines that have been added/removed/modified with respect \
|
|
|
|
to the Git index. Use --diff-context=N to control how much context you want to see.",
|
|
|
|
),
|
2020-04-23 23:39:30 +02:00
|
|
|
)
|
2020-05-13 07:24:51 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("diff-context")
|
2020-05-13 07:24:51 +02:00
|
|
|
.long("diff-context")
|
|
|
|
.overrides_with("diff-context")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("N")
|
2022-09-02 04:06:39 +02:00
|
|
|
.value_parser(
|
|
|
|
|n: &str| {
|
2020-05-13 07:24:51 +02:00
|
|
|
n.parse::<usize>()
|
|
|
|
.map_err(|_| "must be a number")
|
2022-09-02 04:06:39 +02:00
|
|
|
.map(|_| n.to_owned()) // Convert to Result<String, &str>
|
2020-05-13 07:24:51 +02:00
|
|
|
.map_err(|e| e.to_string())
|
|
|
|
}, // Convert to Result<(), String>
|
|
|
|
)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2020-05-13 07:24:51 +02:00
|
|
|
.long_help(
|
|
|
|
"Include N lines of context around added/removed/modified lines when using '--diff'.",
|
|
|
|
),
|
2019-10-24 00:25:02 +02:00
|
|
|
)
|
2020-05-13 07:24:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
app = app.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("tabs")
|
2020-05-13 07:24:51 +02:00
|
|
|
.long("tabs")
|
|
|
|
.overrides_with("tabs")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("T")
|
2022-09-02 04:06:39 +02:00
|
|
|
.value_parser(
|
|
|
|
|t: &str| {
|
2020-05-13 07:24:51 +02:00
|
|
|
t.parse::<u32>()
|
|
|
|
.map_err(|_t| "must be a number")
|
2022-09-02 04:06:39 +02:00
|
|
|
.map(|_t| t.to_owned()) // Convert to Result<String, &str>
|
2020-05-13 07:24:51 +02:00
|
|
|
.map_err(|e| e.to_string())
|
|
|
|
}, // Convert to Result<(), String>
|
|
|
|
)
|
|
|
|
.help("Set the tab width to T spaces.")
|
|
|
|
.long_help(
|
|
|
|
"Set the tab width to T spaces. Use a width of 0 to pass tabs through \
|
2019-10-24 00:25:02 +02:00
|
|
|
directly",
|
2020-05-13 07:24:51 +02:00
|
|
|
),
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("wrap")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("wrap")
|
|
|
|
.overrides_with("wrap")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("mode")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(["auto", "never", "character"])
|
2019-10-24 00:25:02 +02:00
|
|
|
.default_value("auto")
|
|
|
|
.hide_default_value(true)
|
|
|
|
.help("Specify the text-wrapping mode (*auto*, never, character).")
|
|
|
|
.long_help("Specify the text-wrapping mode (*auto*, never, character). \
|
|
|
|
The '--terminal-width' option can be used in addition to \
|
|
|
|
control the output width."),
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("terminal-width")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("terminal-width")
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
2019-10-24 00:25:02 +02:00
|
|
|
.value_name("width")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2019-10-24 00:25:02 +02:00
|
|
|
.allow_hyphen_values(true)
|
2022-09-02 04:06:39 +02:00
|
|
|
.value_parser(
|
|
|
|
|t: &str| {
|
2019-10-24 00:25:02 +02:00
|
|
|
let is_offset = t.starts_with('+') || t.starts_with('-');
|
|
|
|
t.parse::<i32>()
|
|
|
|
.map_err(|_e| "must be an offset or number")
|
|
|
|
.and_then(|v| if v == 0 && !is_offset {
|
2020-04-24 08:46:01 +02:00
|
|
|
Err("terminal width cannot be zero")
|
2019-10-24 00:25:02 +02:00
|
|
|
} else {
|
2022-09-02 04:06:39 +02:00
|
|
|
Ok(t.to_owned())
|
2019-10-24 00:25:02 +02:00
|
|
|
})
|
|
|
|
.map_err(|e| e.to_string())
|
|
|
|
})
|
2018-10-07 10:43:39 +02:00
|
|
|
.help(
|
2019-10-24 00:25:02 +02:00
|
|
|
"Explicitly set the width of the terminal instead of determining it \
|
|
|
|
automatically. If prefixed with '+' or '-', the value will be treated \
|
|
|
|
as an offset to the actual terminal width. See also: '--wrap'.",
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("number")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("number")
|
|
|
|
.overrides_with("number")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('n')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2018-10-03 09:39:30 +02:00
|
|
|
.help("Show line numbers (alias for '--style=numbers').")
|
|
|
|
.long_help(
|
|
|
|
"Only show line numbers, no other decorations. This is an alias for \
|
|
|
|
'--style=numbers'",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("color")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("color")
|
|
|
|
.overrides_with("color")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("when")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(["auto", "never", "always"])
|
2018-10-07 10:43:39 +02:00
|
|
|
.hide_default_value(true)
|
2018-10-03 09:39:30 +02:00
|
|
|
.default_value("auto")
|
2018-10-07 10:43:39 +02:00
|
|
|
.help("When to use colors (*auto*, never, always).")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long_help(
|
|
|
|
"Specify when to use colored output. The automatic mode \
|
2020-07-25 22:32:34 +02:00
|
|
|
only enables colors if an interactive terminal is detected - \
|
|
|
|
colors are automatically disabled if the output goes to a pipe.\n\
|
2018-10-07 10:43:39 +02:00
|
|
|
Possible values: *auto*, never, always.",
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
2018-11-04 18:08:33 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("italic-text")
|
2018-11-04 18:08:33 +01:00
|
|
|
.long("italic-text")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("when")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(["always", "never"])
|
2018-11-04 18:08:33 +01:00
|
|
|
.default_value("never")
|
|
|
|
.hide_default_value(true)
|
|
|
|
.help("Use italics in output (always, *never*)")
|
|
|
|
.long_help("Specify when to use ANSI sequences for italic text in the output. Possible values: always, *never*."),
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("decorations")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("decorations")
|
|
|
|
.overrides_with("decorations")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("when")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(["auto", "never", "always"])
|
2018-10-03 09:39:30 +02:00
|
|
|
.default_value("auto")
|
2018-10-07 10:43:39 +02:00
|
|
|
.hide_default_value(true)
|
|
|
|
.help("When to show the decorations (*auto*, never, always).")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long_help(
|
|
|
|
"Specify when to use the decorations that have been specified \
|
|
|
|
via '--style'. The automatic mode only enables decorations if \
|
2018-10-07 10:43:39 +02:00
|
|
|
an interactive terminal is detected. Possible values: *auto*, never, always.",
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
2020-08-16 05:12:33 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("force-colorization")
|
2020-09-12 04:54:47 +02:00
|
|
|
.long("force-colorization")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('f')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2020-09-12 04:54:47 +02:00
|
|
|
.conflicts_with("color")
|
|
|
|
.conflicts_with("decorations")
|
|
|
|
.overrides_with("force-colorization")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2020-09-12 04:54:47 +02:00
|
|
|
.long_help("Alias for '--decorations=always --color=always'. This is useful \
|
|
|
|
if the output of bat is piped to another program, but you want \
|
|
|
|
to keep the colorization/decorations.")
|
2020-08-16 05:12:33 +02:00
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("paging")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("paging")
|
|
|
|
.overrides_with("paging")
|
2022-08-14 21:09:13 +02:00
|
|
|
.overrides_with("no-paging")
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
|
|
|
.value_name("when")
|
2022-09-02 02:03:25 +02:00
|
|
|
.value_parser(["auto", "never", "always"])
|
2018-10-03 09:39:30 +02:00
|
|
|
.default_value("auto")
|
2018-10-07 10:43:39 +02:00
|
|
|
.hide_default_value(true)
|
2020-07-02 09:07:37 +02:00
|
|
|
.help("Specify when to use the pager, or use `-P` to disable (*auto*, never, always).")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long_help(
|
2020-07-02 09:07:37 +02:00
|
|
|
"Specify when to use the pager. To disable the pager, use \
|
|
|
|
--paging=never' or its alias,'-P'. To disable the pager permanently, \
|
|
|
|
set BAT_PAGER to an empty string. To control which pager is used, see the \
|
|
|
|
'--pager' option. Possible values: *auto*, never, always."
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
2020-06-30 21:18:17 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("no-paging")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('P')
|
2021-08-09 10:54:32 +02:00
|
|
|
.long("no-paging")
|
2020-07-02 06:35:45 +02:00
|
|
|
.alias("no-pager")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2020-07-02 06:35:45 +02:00
|
|
|
.overrides_with("no-paging")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
|
|
|
.hide_short_help(true)
|
2020-07-02 09:07:37 +02:00
|
|
|
.help("Alias for '--paging=never'")
|
2020-06-30 21:18:17 +02:00
|
|
|
)
|
2018-10-21 12:52:29 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("pager")
|
2018-10-21 12:52:29 +02:00
|
|
|
.long("pager")
|
|
|
|
.overrides_with("pager")
|
|
|
|
.takes_value(true)
|
2018-10-21 22:13:28 +02:00
|
|
|
.value_name("command")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2018-10-21 22:13:28 +02:00
|
|
|
.help("Determine which pager to use.")
|
2018-10-21 12:52:29 +02:00
|
|
|
.long_help(
|
2020-07-02 09:07:37 +02:00
|
|
|
"Determine which pager is used. This option will override the \
|
|
|
|
PAGER and BAT_PAGER environment variables. The default pager is 'less'. \
|
|
|
|
To control when the pager is used, see the '--paging' option. \
|
|
|
|
Example: '--pager \"less -RF\"'."
|
2018-10-21 12:52:29 +02:00
|
|
|
),
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("map-syntax")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('m')
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("map-syntax")
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Append)
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
2020-03-22 10:37:18 +01:00
|
|
|
.value_name("glob:syntax")
|
|
|
|
.help("Use the specified syntax for files matching the glob pattern ('*.cpp:C++').")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long_help(
|
2020-03-22 10:37:18 +01:00
|
|
|
"Map a glob pattern to an existing syntax name. The glob pattern is matched \
|
|
|
|
on the full path and the filename. For example, to highlight *.build files \
|
|
|
|
with the Python syntax, use -m '*.build:Python'. To highlight files named \
|
2021-01-10 16:21:17 +01:00
|
|
|
'.myignore' with the Git Ignore syntax, use -m '.myignore:Git Ignore'. Note \
|
|
|
|
that the right-hand side is the *name* of the syntax, not a file extension.",
|
2019-10-24 00:25:02 +02:00
|
|
|
)
|
|
|
|
.takes_value(true),
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
2022-01-07 10:38:57 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("ignored-suffix")
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Append)
|
2022-01-07 10:38:57 +01:00
|
|
|
.takes_value(true)
|
|
|
|
.long("ignored-suffix")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2022-01-07 10:38:57 +01:00
|
|
|
.help(
|
|
|
|
"Ignore extension. For example:\n \
|
|
|
|
'bat --ignored-suffix \".dev\" my_file.json.dev' will use JSON syntax, and ignore '.dev'"
|
|
|
|
)
|
|
|
|
)
|
2018-10-03 09:39:30 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("theme")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("theme")
|
|
|
|
.overrides_with("theme")
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
2019-10-24 00:25:02 +02:00
|
|
|
.help("Set the color theme for syntax highlighting.")
|
|
|
|
.long_help(
|
|
|
|
"Set the theme for syntax highlighting. Use '--list-themes' to \
|
|
|
|
see all available themes. To set a default theme, add the \
|
|
|
|
'--theme=\"...\"' option to the configuration file or export the \
|
|
|
|
BAT_THEME environment variable (e.g.: export \
|
|
|
|
BAT_THEME=\"...\").",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("list-themes")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("list-themes")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2019-10-24 00:25:02 +02:00
|
|
|
.help("Display all supported highlighting themes.")
|
|
|
|
.long_help("Display a list of supported themes for syntax highlighting."),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("style")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("style")
|
2020-03-22 10:37:18 +01:00
|
|
|
.value_name("components")
|
2019-10-24 00:25:02 +02:00
|
|
|
// Need to turn this off for overrides_with to work as we want. See the bottom most
|
|
|
|
// example at https://docs.rs/clap/2.32.0/clap/struct.Arg.html#method.overrides_with
|
2022-09-02 02:03:25 +02:00
|
|
|
.use_value_delimiter(false)
|
2019-10-24 00:25:02 +02:00
|
|
|
.takes_value(true)
|
|
|
|
.overrides_with("style")
|
|
|
|
.overrides_with("plain")
|
|
|
|
.overrides_with("number")
|
2020-09-20 21:00:04 +02:00
|
|
|
// Cannot use claps built in validation because we have to turn off clap's delimiters
|
2022-09-02 04:06:39 +02:00
|
|
|
.value_parser(|val: &str| {
|
2019-10-24 00:25:02 +02:00
|
|
|
let mut invalid_vals = val.split(',').filter(|style| {
|
|
|
|
!&[
|
2022-02-07 20:48:57 +01:00
|
|
|
"auto",
|
|
|
|
"full",
|
2022-05-04 21:31:32 +02:00
|
|
|
"default",
|
2022-02-07 20:48:57 +01:00
|
|
|
"plain",
|
|
|
|
"header",
|
|
|
|
"header-filename",
|
|
|
|
"header-filesize",
|
|
|
|
"grid",
|
|
|
|
"rule",
|
|
|
|
"numbers",
|
|
|
|
"snip",
|
2020-05-13 07:24:51 +02:00
|
|
|
#[cfg(feature = "git")]
|
2022-02-07 20:48:57 +01:00
|
|
|
"changes",
|
|
|
|
].contains(style)
|
2019-10-24 00:25:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if let Some(invalid) = invalid_vals.next() {
|
|
|
|
Err(format!("Unknown style, '{}'", invalid))
|
|
|
|
} else {
|
2022-09-02 04:06:39 +02:00
|
|
|
Ok(val.to_owned())
|
2019-10-24 00:25:02 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.help(
|
|
|
|
"Comma-separated list of style elements to display \
|
2022-05-04 21:31:32 +02:00
|
|
|
(*default*, auto, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).",
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
|
|
|
.long_help(
|
2019-10-24 00:25:02 +02:00
|
|
|
"Configure which elements (line numbers, file headers, grid \
|
|
|
|
borders, Git modifications, ..) to display in addition to the \
|
|
|
|
file contents. The argument is a comma-separated list of \
|
|
|
|
components to display (e.g. 'numbers,changes,grid') or a \
|
|
|
|
pre-defined style ('full'). To set a default style, add the \
|
|
|
|
'--style=\"..\"' option to the configuration file or export the \
|
2020-09-20 21:00:04 +02:00
|
|
|
BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\
|
|
|
|
Possible values:\n\n \
|
2022-05-04 21:31:32 +02:00
|
|
|
* default: enables recommended style components (default).\n \
|
|
|
|
* full: enables all available components.\n \
|
|
|
|
* auto: same as 'default', unless the output is piped.\n \
|
2020-09-20 21:00:04 +02:00
|
|
|
* plain: disables all available components.\n \
|
|
|
|
* changes: show Git modification markers.\n \
|
2022-02-07 20:48:57 +01:00
|
|
|
* header: alias for 'header-filename'.\n \
|
|
|
|
* header-filename: show filenames before the content.\n \
|
|
|
|
* header-filesize: show file sizes before the content.\n \
|
2020-09-20 21:00:04 +02:00
|
|
|
* grid: vertical/horizontal lines to separate side bar\n \
|
|
|
|
and the header from the content.\n \
|
2020-10-06 17:57:47 +02:00
|
|
|
* rule: horizontal lines to delimit files.\n \
|
2020-09-20 21:00:04 +02:00
|
|
|
* numbers: show line numbers in the side bar.\n \
|
|
|
|
* snip: draw separation lines between distinct line ranges.",
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
2019-10-24 00:25:02 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("line-range")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("line-range")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('r')
|
2022-09-02 03:35:49 +02:00
|
|
|
.action(ArgAction::Append)
|
2019-10-24 00:25:02 +02:00
|
|
|
.takes_value(true)
|
|
|
|
.value_name("N:M")
|
|
|
|
.help("Only print the lines from N to M.")
|
|
|
|
.long_help(
|
|
|
|
"Only print the specified range of lines for each file. \
|
|
|
|
For example:\n \
|
|
|
|
'--line-range 30:40' prints lines 30 to 40\n \
|
|
|
|
'--line-range :40' prints lines 1 to 40\n \
|
2020-01-23 04:26:21 +01:00
|
|
|
'--line-range 40:' prints lines 40 to the end of the file\n \
|
2021-08-21 19:55:52 +02:00
|
|
|
'--line-range 40' only prints line 40\n \
|
|
|
|
'--line-range 30:+10' prints lines 30 to 40",
|
2019-10-24 00:25:02 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("list-languages")
|
2019-10-24 00:25:02 +02:00
|
|
|
.long("list-languages")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('L')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2019-10-24 00:25:02 +02:00
|
|
|
.conflicts_with("list-themes")
|
|
|
|
.help("Display all supported languages.")
|
|
|
|
.long_help("Display a list of supported languages for syntax highlighting."),
|
|
|
|
)
|
2018-10-07 10:43:39 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("unbuffered")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('u')
|
2018-10-07 10:43:39 +02:00
|
|
|
.long("unbuffered")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2018-10-07 10:43:39 +02:00
|
|
|
.long_help(
|
|
|
|
"This option exists for POSIX-compliance reasons ('u' is for \
|
|
|
|
'unbuffered'). The output is always unbuffered - this option \
|
|
|
|
is simply ignored.",
|
|
|
|
),
|
|
|
|
)
|
2018-10-11 21:40:14 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("no-config")
|
2018-10-11 21:40:14 +02:00
|
|
|
.long("no-config")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2018-10-11 21:40:14 +02:00
|
|
|
.help("Do not use the configuration file"),
|
|
|
|
)
|
2021-07-27 20:11:58 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("no-custom-assets")
|
2021-07-27 20:11:58 +02:00
|
|
|
.long("no-custom-assets")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2021-07-27 20:11:58 +02:00
|
|
|
.help("Do not load custom assets"),
|
|
|
|
)
|
2018-10-17 23:02:53 +02:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("config-file")
|
2018-10-17 23:02:53 +02:00
|
|
|
.long("config-file")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2018-10-17 23:02:53 +02:00
|
|
|
.conflicts_with("list-languages")
|
|
|
|
.conflicts_with("list-themes")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2018-10-17 23:17:28 +02:00
|
|
|
.help("Show path to the configuration file."),
|
2018-10-17 23:02:53 +02:00
|
|
|
)
|
2020-03-24 03:08:19 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("generate-config-file")
|
2020-03-24 03:08:19 +01:00
|
|
|
.long("generate-config-file")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2020-03-24 03:08:19 +01:00
|
|
|
.conflicts_with("list-languages")
|
|
|
|
.conflicts_with("list-themes")
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2020-03-24 03:08:19 +01:00
|
|
|
.help("Generates a default configuration file."),
|
|
|
|
)
|
2019-02-07 22:37:12 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("config-dir")
|
2019-02-07 22:37:12 +01:00
|
|
|
.long("config-dir")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2019-02-07 22:37:12 +01:00
|
|
|
.help("Show bat's configuration directory."),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("cache-dir")
|
2019-02-07 22:37:12 +01:00
|
|
|
.long("cache-dir")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide(true)
|
2019-02-07 22:37:12 +01:00
|
|
|
.help("Show bat's cache directory."),
|
|
|
|
)
|
2020-12-31 18:17:15 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("diagnostic")
|
2020-12-31 18:17:15 +01:00
|
|
|
.long("diagnostic")
|
2021-01-06 22:25:23 +01:00
|
|
|
.alias("diagnostics")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2020-12-31 18:17:15 +01:00
|
|
|
.help("Show diagnostic information for bug reports.")
|
|
|
|
)
|
2021-12-11 14:00:45 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("acknowledgements")
|
2021-12-11 14:00:45 +01:00
|
|
|
.long("acknowledgements")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2022-09-02 02:03:25 +02:00
|
|
|
.hide_short_help(true)
|
2021-12-11 14:00:45 +01:00
|
|
|
.help("Show acknowledgements."),
|
|
|
|
)
|
2022-09-02 02:03:25 +02:00
|
|
|
.mut_arg("help", |arg| arg.help("Print this help message."));
|
2019-09-21 09:10:12 +02:00
|
|
|
|
|
|
|
// Check if the current directory contains a file name cache. Otherwise,
|
|
|
|
// enable the 'bat cache' subcommand.
|
|
|
|
if Path::new("cache").exists() {
|
|
|
|
app
|
|
|
|
} else {
|
|
|
|
app.subcommand(
|
2022-09-02 02:03:25 +02:00
|
|
|
Command::new("cache")
|
2018-10-03 09:39:30 +02:00
|
|
|
.about("Modify the syntax-definition and theme cache")
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("build")
|
2019-02-07 22:31:37 +01:00
|
|
|
.long("build")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('b')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2019-02-07 22:31:37 +01:00
|
|
|
.help("Initialize (or update) the syntax/theme cache.")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long_help(
|
2019-02-07 22:31:37 +01:00
|
|
|
"Initialize (or update) the syntax/theme cache by loading from \
|
|
|
|
the source directory (default: the configuration directory).",
|
2018-10-03 09:39:30 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("clear")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("clear")
|
2022-09-01 22:41:07 +02:00
|
|
|
.short('c')
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2018-10-03 09:39:30 +02:00
|
|
|
.help("Remove the cached syntax definitions and themes."),
|
|
|
|
)
|
|
|
|
.group(
|
2022-09-02 02:03:25 +02:00
|
|
|
ArgGroup::new("cache-actions")
|
2019-02-07 22:37:12 +01:00
|
|
|
.args(&["build", "clear"])
|
2019-09-21 09:10:12 +02:00
|
|
|
.required(true),
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("source")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("source")
|
2019-02-07 22:31:37 +01:00
|
|
|
.requires("build")
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
|
|
|
.value_name("dir")
|
|
|
|
.help("Use a different directory to load syntaxes and themes from."),
|
|
|
|
)
|
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("target")
|
2018-10-03 09:39:30 +02:00
|
|
|
.long("target")
|
2019-02-07 22:31:37 +01:00
|
|
|
.requires("build")
|
2018-10-03 09:39:30 +02:00
|
|
|
.takes_value(true)
|
|
|
|
.value_name("dir")
|
|
|
|
.help(
|
|
|
|
"Use a different directory to store the cached syntax and theme set.",
|
|
|
|
),
|
|
|
|
)
|
2022-09-02 03:53:37 +02:00
|
|
|
.arg(
|
|
|
|
Arg::new("blank")
|
|
|
|
.long("blank")
|
|
|
|
.action(ArgAction::SetTrue)
|
|
|
|
.requires("build")
|
|
|
|
.help(
|
|
|
|
"Create completely new syntax and theme sets \
|
2019-09-21 09:10:12 +02:00
|
|
|
(instead of appending to the default sets).",
|
2022-09-02 03:53:37 +02:00
|
|
|
),
|
|
|
|
)
|
2021-12-11 14:00:45 +01:00
|
|
|
.arg(
|
2022-09-02 02:03:25 +02:00
|
|
|
Arg::new("acknowledgements")
|
2021-12-11 14:00:45 +01:00
|
|
|
.long("acknowledgements")
|
2022-09-02 03:53:37 +02:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-12-11 14:00:45 +01:00
|
|
|
.requires("build")
|
|
|
|
.help("Build acknowledgements.bin."),
|
2019-09-21 09:10:12 +02:00
|
|
|
),
|
2018-10-03 09:39:30 +02:00
|
|
|
)
|
2019-09-21 09:10:12 +02:00
|
|
|
}
|
2018-10-03 09:39:30 +02:00
|
|
|
}
|
2022-09-01 22:41:07 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn verify_app() {
|
|
|
|
build_app(false).debug_assert();
|
|
|
|
}
|