on master help sign in
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.

commit9c371ed8a26dc51038c79b79e43f2f6e28461f5a authorEthan P <32112321+eth-p@users.noreply.github.com> dateFri 15 May 2020, 16:41 (6 years ago) parentd08d1f8f03ab11
6 files changed+79−60
CHANGELOG.md+3 src/bin/bat/app.rs+7−6 src/bin/bat/clap_app.rs+62−52 src/pretty_printer.rs+2 src/printer.rs+1−2 src/style.rs+4
CHANGELOG.md+3
@@ -13,6 +13,9 @@
1313## New syntaxes
1414## New themes
1515## `bat` as a library
16+
17+- `PrettyPrinter::vcs_modification_markers` is no longer available without the `git` feature, see #997 (@eth-p)
18+
1619## Packaging
1720
1821# v0.15.1
src/bin/bat/app.rs+7−6
@@ -198,22 +198,23 @@ impl App {
198198 }
199199 })
200200 .unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
201− visible_lines: if self.matches.is_present("diff") {
202− VisibleLines::DiffContext(
201+ visible_lines: match self.matches.is_present("diff") {
202+ #[cfg(feature = "git")]
203+ true => VisibleLines::DiffContext(
203204 self.matches
204205 .value_of("diff-context")
205206 .and_then(|t| t.parse().ok())
206207 .unwrap_or(2),
207− )
208− } else {
209− VisibleLines::Ranges(
208+ ),
209+
210+ _ => VisibleLines::Ranges(
210211 self.matches
211212 .values_of("line-range")
212213 .map(|vs| vs.map(LineRange::from).collect())
213214 .transpose()?
214215 .map(LineRanges::from)
215216 .unwrap_or_default(),
216− )
217+ ),
217218 },
218219 style_components,
219220 syntax_mapping,
src/bin/bat/clap_app.rs+62−52
@@ -8,7 +8,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
88 AppSettings::ColorNever
99 };
1010
11− let app = ClapApp::new(crate_name!())
11+ let mut app = ClapApp::new(crate_name!())
1212 .version(crate_version!())
1313 .global_setting(clap_color_setting)
1414 .global_setting(AppSettings::DeriveDisplayOrder)
@@ -44,7 +44,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
4444 .long_help(
4545 "Show non-printable characters like space, tab or newline. \
4646 This option can also be used to print binary files. \
47− Use '--tabs' to control the width of the tab-placeholders."
47+ Use '--tabs' to control the width of the tab-placeholders.",
4848 ),
4949 )
5050 .arg(
@@ -90,7 +90,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
9090 '--highlight-line 40' highlights line 40\n \
9191 '--highlight-line 30:40' highlights lines 30 to 40\n \
9292 '--highlight-line :40' highlights lines 1 to 40\n \
93− '--highlight-line 40:' highlights lines 40 to the end of the file"
93+ '--highlight-line 40:' highlights lines 40 to the end of the file",
9494 ),
9595 )
9696 .arg(
@@ -101,59 +101,67 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
101101 .multiple(true)
102102 .value_name("name")
103103 .help("Specify the name to display for a file.")
104− .long_help("Specify the name to display for a file. Useful when piping \
105− data to bat from STDIN when bat does not otherwise know \
106− the filename."),
107− )
108− .arg(
109− Arg::with_name("diff")
110− .long("diff")
111− .short("d")
112− .help("Only show lines that have been added/removed/modified.")
113104 .long_help(
114− "Only show lines that have been added/removed/modified with respect \
115− to the Git index. Use --diff-context=N to control how much context you want to see.",
105+ "Specify the name to display for a file. Useful when piping \
106+ data to bat from STDIN when bat does not otherwise know \
107+ the filename.",
116108 ),
117− )
118− .arg(
119− Arg::with_name("diff-context")
120− .long("diff-context")
121− .overrides_with("diff-context")
122− .takes_value(true)
123− .value_name("N")
124− .validator(
125− |n| {
126− n.parse::<usize>()
127− .map_err(|_| "must be a number")
128− .map(|_| ()) // Convert to Result<(), &str>
129− .map_err(|e| e.to_string())
130− }, // Convert to Result<(), String>
109+ );
110+
111+ #[cfg(feature = "git")]
112+ {
113+ app = app
114+ .arg(
115+ Arg::with_name("diff")
116+ .long("diff")
117+ .short("d")
118+ .help("Only show lines that have been added/removed/modified.")
119+ .long_help(
120+ "Only show lines that have been added/removed/modified with respect \
121+ to the Git index. Use --diff-context=N to control how much context you want to see.",
122+ ),
131123 )
132− .hidden_short_help(true)
133− .long_help(
134− "Include N lines of context around added/removed/modified lines when using '--diff'.",
135− ),
136− )
137− .arg(
138− Arg::with_name("tabs")
139− .long("tabs")
140− .overrides_with("tabs")
141− .takes_value(true)
142− .value_name("T")
143− .validator(
144− |t| {
145− t.parse::<u32>()
146− .map_err(|_t| "must be a number")
147− .map(|_t| ()) // Convert to Result<(), &str>
148− .map_err(|e| e.to_string())
149− }, // Convert to Result<(), String>
124+ .arg(
125+ Arg::with_name("diff-context")
126+ .long("diff-context")
127+ .overrides_with("diff-context")
128+ .takes_value(true)
129+ .value_name("N")
130+ .validator(
131+ |n| {
132+ n.parse::<usize>()
133+ .map_err(|_| "must be a number")
134+ .map(|_| ()) // Convert to Result<(), &str>
135+ .map_err(|e| e.to_string())
136+ }, // Convert to Result<(), String>
137+ )
138+ .hidden_short_help(true)
139+ .long_help(
140+ "Include N lines of context around added/removed/modified lines when using '--diff'.",
141+ ),
150142 )
151− .help("Set the tab width to T spaces.")
152− .long_help(
153− "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
143+ }
144+
145+ app = app.arg(
146+ Arg::with_name("tabs")
147+ .long("tabs")
148+ .overrides_with("tabs")
149+ .takes_value(true)
150+ .value_name("T")
151+ .validator(
152+ |t| {
153+ t.parse::<u32>()
154+ .map_err(|_t| "must be a number")
155+ .map(|_t| ()) // Convert to Result<(), &str>
156+ .map_err(|e| e.to_string())
157+ }, // Convert to Result<(), String>
158+ )
159+ .help("Set the tab width to T spaces.")
160+ .long_help(
161+ "Set the tab width to T spaces. Use a width of 0 to pass tabs through \
154162 directly",
155− ),
156− )
163+ ),
164+ )
157165 .arg(
158166 Arg::with_name("wrap")
159167 .long("wrap")
@@ -334,7 +342,9 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
334342 .validator(|val| {
335343 let mut invalid_vals = val.split(',').filter(|style| {
336344 !&[
337− "auto", "full", "plain", "changes", "header", "grid", "numbers", "snip"
345+ "auto", "full", "plain", "header", "grid", "numbers", "snip",
346+ #[cfg(feature = "git")]
347+ "changes",
338348 ]
339349 .contains(style)
340350 });
src/pretty_printer.rs+2
@@ -166,6 +166,7 @@ impl<'a> PrettyPrinter<'a> {
166166 }
167167
168168 /// Whether to show modification markers for VCS changes
169+ #[cfg(feature = "git")]
169170 pub fn vcs_modification_markers(&mut self, yes: bool) -> &mut Self {
170171 self.active_style_components.vcs_modification_markers = yes;
171172 self
@@ -269,6 +270,7 @@ impl<'a> PrettyPrinter<'a> {
269270 style_components.push(StyleComponent::Snip);
270271 }
271272 if self.active_style_components.vcs_modification_markers {
273+ #[cfg(feature = "git")]
272274 style_components.push(StyleComponent::Changes);
273275 }
274276 self.config.style_components = StyleComponents::new(&style_components);
src/printer.rs+1−2
@@ -111,8 +111,7 @@ impl<'a> InteractivePrinter<'a> {
111111 config: &'a Config,
112112 assets: &'a HighlightingAssets,
113113 input: &mut OpenedInput,
114− #[cfg(feature = "git")]
115− line_changes: &'a Option<LineChanges>,
114+ #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
116115 ) -> Self {
117116 let theme = assets.get_theme(&config.theme);
118117
src/style.rs+4
@@ -6,6 +6,7 @@ use crate::error::*;
66#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
77pub enum StyleComponent {
88 Auto,
9+ #[cfg(feature = "git")]
910 Changes,
1011 Grid,
1112 Header,
@@ -25,12 +26,14 @@ impl StyleComponent {
2526 StyleComponent::Plain.components(interactive_terminal)
2627 }
2728 }
29+ #[cfg(feature = "git")]
2830 StyleComponent::Changes => &[StyleComponent::Changes],
2931 StyleComponent::Grid => &[StyleComponent::Grid],
3032 StyleComponent::Header => &[StyleComponent::Header],
3133 StyleComponent::LineNumbers => &[StyleComponent::LineNumbers],
3234 StyleComponent::Snip => &[StyleComponent::Snip],
3335 StyleComponent::Full => &[
36+ #[cfg(feature = "git")]
3437 StyleComponent::Changes,
3538 StyleComponent::Grid,
3639 StyleComponent::Header,
@@ -48,6 +51,7 @@ impl FromStr for StyleComponent {
4851 fn from_str(s: &str) -> Result<Self> {
4952 match s {
5053 "auto" => Ok(StyleComponent::Auto),
54+ #[cfg(feature = "git")]
5155 "changes" => Ok(StyleComponent::Changes),
5256 "grid" => Ok(StyleComponent::Grid),
5357 "header" => Ok(StyleComponent::Header),