summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan P <32112321+eth-p@users.noreply.github.com>2020-05-15 16:41:13 -0700
committerGitHub <noreply@github.com>2020-05-15 16:41:13 -0700
commit9c371ed8a26dc51038c79b79e43f2f6e28461f5a (patch)
tree29cb5a0dd98fd4ca7e7492c63cef3f2ad5e5c0f6
parentd08d1f8c4599e96a96a821499aeb46383619ce89 (diff)
parentf03ab116239ee21b3450cbed82cb5b8f8a6b1e59 (diff)
Merge pull request #997 from eth-p/misc-fixes-1
Allow 'bat' application to built without git feature, remove PrettyPrint git support when feature not enabled.
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/bin/bat/app.rs13
-rw-r--r--src/bin/bat/clap_app.rs114
-rw-r--r--src/pretty_printer.rs2
-rw-r--r--src/printer.rs3
-rw-r--r--src/style.rs4
6 files changed, 79 insertions, 60 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69aae01d..63b5b241 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@
## New syntaxes
## New themes
## `bat` as a library
+
+- `PrettyPrinter::vcs_modification_markers` is no longer available without the `git` feature, see #997 (@eth-p)
+
## Packaging
# v0.15.1
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index d5751f73..4aa742a0 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -198,22 +198,23 @@ impl App {
}
})
.unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
- visible_lines: if self.matches.is_present("diff") {
- VisibleLines::DiffContext(
+ visible_lines: match self.matches.is_present("diff") {
+ #[cfg(feature = "git")]
+ true => VisibleLines::DiffContext(
self.matches
.value_of("diff-context")
.and_then(|t| t.parse().ok())
.unwrap_or(2),
- )
- } else {
- VisibleLines::Ranges(
+ ),
+
+ _ => VisibleLines::Ranges(
self.matches
.values_of("line-range")
.map(|vs| vs.map(LineRange::from).collect())
.transpose()?
.map(LineRanges::from)
.unwrap_or_default(),
- )
+ ),
},
style_components,
syntax_mapping,
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index 9377bf1d..9441182b 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -8,7 +8,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
AppSettings::ColorNever
};
- let app = ClapApp::new(crate_name!())
+ let mut app = ClapApp::new(crate_name!())
.version(crate_version!())
.global_setting(clap_color_setting)
.global_setting(AppSettings::DeriveDisplayOrder)
@@ -44,7 +44,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.long_help(
"Show non-printable characters like space, tab or newline. \
This option can also be used to print binary files. \
- Use '--tabs' to control the width of the tab-placeholders."
+ Use '--tabs' to control the width of the tab-placeholders.",
),
)
.arg(
@@ -90,7 +90,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
'--highlight-line 40' highlights line 40\n \
'--highlight-line 30:40' highlights lines 30 to 40\n \
'--highlight-line :40' highlights lines 1 to 40\n \
- '--highlight-line 40:' highlights lines 40 to the end of the file"
+ '--highlight-line 40:' highlights lines 40 to the end of the file",
),
)
.arg(
@@ -101,59 +101,67 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.multiple(true)
.value_name("name")
.help("Specify the name to display for a file.")
- .long_help("Specify the name to display for a file. Useful when piping \
- data to bat from STDIN when bat does not otherwise know \
- the filename."),
- )
- .arg(
- Arg::with_name("diff")
- .long("diff")
- .short("d")
- .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.",
+ "Specify the name to display for a file. Useful when piping \
+ data to bat from STDIN when bat does not otherwise know \
+ the filename.",
),
- )
- .arg(
- Arg::with_name("diff-context")
- .long("diff-context")
- .overrides_with("diff-context")
- .takes_value(true)
- .value_name("N")
- .validator(
- |n| {
- n.parse::<usize>()
- .map_err(|_| "must be a number")
- .map(|_| ()) // Convert to Result<(), &str>
- .map_err(|e| e.to_string())
- }, // Convert to Result<(), String>
+ );
+
+ #[cfg(feature = "git")]
+ {
+ app = app
+ .arg(
+ Arg::with_name("diff")
+ .long("diff")
+ .short("d")
+ .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.",
+ ),
)
- .hidden_short_help(true)
- .long_help(
- "Include N lines of context around added/removed/modified lines when using '--diff'.",
- ),
- )
- .arg(
- Arg::with_name("tabs")
- .long("tabs")
- .overrides_with("tabs")
- .takes_value(true)
- .value_name("T")
- .validator(
- |t| {
- t.parse::<u32>()
- .map_err(|_t| "must be a number")
- .map(|_t| ()) // Convert to Result<(), &str>
- .map_err(|e| e.to_string())
- }, // Convert to Result<(), String>
+ .arg(
+ Arg::with_name("diff-context")
+ .long("diff-context")
+ .overrides_with("diff-context")
+ .takes_value(true)
+ .value_name("N")
+ .validator(
+ |n| {
+ n.parse::<usize>()
+ .map_err(|_| "must be a number")
+ .map(|_| ()) // Convert to Result<(), &str>
+ .map_err(|e| e.to_string())
+ }, // Convert to Result<(), String>
+ )
+ .hidden_short_help(true)
+ .long_help(
+ "Include N lines of context around added/removed/modified lines when using '--diff'.",
+ ),
)
- .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 \
+ }
+
+ app = app.arg(
+ Arg::with_name("tabs")
+ .long("tabs")
+ .overrides_with("tabs")
+ .takes_value(true)
+ .value_name("T")
+ .validator(
+ |t| {
+ t.parse::<u32>()
+ .map_err(|_t| "must be a number")
+ .map(|_t| ()) // Convert to Result<(), &str>
+ .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 \
directly",
- ),
- )
+ ),
+ )
.arg(
Arg::with_name("wrap")
.long("wrap")
@@ -334,7 +342,9 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.validator(|val| {
let mut invalid_vals = val.split(',').filter(|style| {
!&[
- "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
+ "auto", "full", "plain", "header", "grid", "numbers", "snip",
+ #[cfg(feature = "git")]
+ "changes",
]
.contains(style)
});
diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
index 13bd5dbc..da60abbd 100644
--- a/src/pretty_printer.rs
+++ b/src/pretty_printer.rs
@@ -166,6 +166,7 @@ impl<'a> PrettyPrinter<'a> {
}
/// Whether to show modification markers for VCS changes
+ #[cfg(feature = "git")]
pub fn vcs_modification_markers(&mut self, yes: bool) -> &mut Self {
self.active_style_components.vcs_modification_markers = yes;
self
@@ -269,6 +270,7 @@ impl<'a> PrettyPrinter<'a> {
style_components.push(StyleComponent::Snip);
}
if self.active_style_components.vcs_modification_markers {
+ #[cfg(feature = "git")]
style_components.push(StyleComponent::Changes);
}
self.config.style_components = StyleComponents::new(&style_components);
diff --git a/src/printer.rs b/src/printer.rs
index cfc9d1af..3d8fa9bf 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -111,8 +111,7 @@ impl<'a> InteractivePrinter<'a> {
config: &'a Config,
assets: &'a HighlightingAssets,
input: &mut OpenedInput,
- #[cfg(feature = "git")]
- line_changes: &'a Option<LineChanges>,
+ #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
) -> Self {
let theme = assets.get_theme(&config.theme);
diff --git a/src/style.rs b/src/style.rs
index 24fffd6b..8d51cbde 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -6,6 +6,7 @@ use crate::error::*;
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
pub enum StyleComponent {
Auto,
+ #[cfg(feature = "git")]
Changes,
Grid,
Header,
@@ -25,12 +26,14 @@ impl StyleComponent {
StyleComponent::Plain.components(interactive_terminal)
}
}
+ #[cfg(feature = "git")]
StyleComponent::Changes => &[StyleComponent::Changes],
StyleComponent::Grid => &[StyleComponent::Grid],
StyleComponent::Header => &[StyleComponent::Header],
StyleComponent::LineNumbers => &[StyleComponent::LineNumbers],
StyleComponent::Snip => &[StyleComponent::Snip],
StyleComponent::Full => &[
+ #[cfg(feature = "git")]
StyleComponent::Changes,
StyleComponent::Grid,
StyleComponent::Header,
@@ -48,6 +51,7 @@ impl FromStr for StyleComponent {
fn from_str(s: &str) -> Result<Self> {
match s {
"auto" => Ok(StyleComponent::Auto),
+ #[cfg(feature = "git")]
"changes" => Ok(StyleComponent::Changes),
"grid" => Ok(StyleComponent::Grid),
"header" => Ok(StyleComponent::Header),