Use less binary specified in bat config for --diagnostic

This commit is contained in:
Ethan P 2021-01-10 13:57:05 -08:00 committed by David Peter
parent 025c5c061b
commit f874c8e4db
2 changed files with 12 additions and 1 deletions

View File

@ -229,6 +229,8 @@ fn run() -> Result<bool> {
if app.matches.is_present("diagnostic") {
use bugreport::{bugreport, collector::*, format::Markdown};
let pager = bat::config::get_pager_executable(app.matches.value_of("pager"))
.unwrap_or("less".to_owned()); // FIXME: Avoid non-canonical path to "less".
bugreport!()
.info(SoftwareVersion::default())
@ -252,7 +254,7 @@ fn run() -> Result<bool> {
]))
.info(FileContent::new("Config file", config_file()))
.info(CompileTimeInformation::default())
.info(CommandOutput::new("Less version", "less", &["--version"]))
.info(CommandOutput::new("Less version", pager, &["--version"]))
.print::<Markdown>();
return Ok(true);

View File

@ -84,6 +84,15 @@ pub struct Config<'a> {
pub highlighted_lines: HighlightedLineRanges,
}
#[cfg(all(feature = "application", feature = "paging"))]
pub fn get_pager_executable(config_pager: Option<&str>) -> Option<String> {
if let Ok(Some(pager)) = crate::pager::get_pager(config_pager) {
Some(pager.bin)
} else {
None
}
}
#[test]
fn default_config_should_include_all_lines() {
use crate::line_range::RangeCheckResult;