Skip to content

Commit

Permalink
Improvements from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
clnoll committed Nov 23, 2022
1 parent 369a044 commit 157b8e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
28 changes: 13 additions & 15 deletions src/subcommands/doctor/less.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ impl Less {
impl Diagnostic for Less {
fn report(&self) -> (String, bool) {
match self.version {
Some(n) => match n < self.min_version {
true => (
format!(
"`less` version >= {} is required (your version: {})",
MIN_LESS_VERSION, n
),
false,
Some(n) if n < self.min_version => (
format!(
"`less` version >= {} is required (your version: {})",
MIN_LESS_VERSION, n
),
false => (
format!(
"`less` version >= {} is required (your version: {})",
MIN_LESS_VERSION, n
),
true,
false,
),
Some(n) if n >= self.min_version => (
format!(
"`less` version >= {} is required (your version: {})",
MIN_LESS_VERSION, n
),
},
None => ("`less` version >= {} is required".to_string(), false),
true,
),
_ => ("`less` version >= {} is required".to_string(), false),
}
}

Expand Down
42 changes: 22 additions & 20 deletions src/subcommands/doctor/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,40 @@ pub fn run_diagnostics() -> std::io::Result<()> {
Box::new(PagerEnvVars::probe()),
];

let mut reports = Vec::new();
for d in diagnostics {
reports.push(build_report_row(d));
}
let reports = diagnostics
.into_iter()
.map(|d| Report::from_diagnostic(d))
.collect();

print_table(reports);
Ok(())
}

fn build_report_row(diagnostic: Box<dyn Diagnostic>) -> Report {
let remedy = diagnostic.remedy();
match remedy {
Some(r) => Report {
result: "❌".to_string(),
description: diagnostic.report().0,
remedy: r,
},
None => Report {
result: "✅".to_string(),
description: diagnostic.report().0,
remedy: "".to_string(),
},
}
}

#[derive(Tabled)]
struct Report {
result: String,
description: String,
remedy: String,
}

impl Report {
pub fn from_diagnostic(diagnostic: Box<dyn Diagnostic>) -> Self {
let remedy = diagnostic.remedy();
match remedy {
Some(r) => Report {
result: "❌".to_string(),
description: diagnostic.report().0,
remedy: r,
},
None => Report {
result: "✅".to_string(),
description: diagnostic.report().0,
remedy: "".to_string(),
},
}
}
}

fn print_table(report: Vec<Report>) {
let mut table = Table::new(&report);
table.with(Style::modern());
Expand Down

0 comments on commit 157b8e8

Please sign in to comment.