Skip to content

Work in Progress: Initial implementation of --doctor command#1193

Open
clnoll wants to merge 9 commits into
dandavison:mainfrom
clnoll:doctor
Open

Work in Progress: Initial implementation of --doctor command#1193
clnoll wants to merge 9 commits into
dandavison:mainfrom
clnoll:doctor

Conversation

@clnoll

@clnoll clnoll commented Sep 15, 2022

Copy link
Copy Markdown
Contributor

This is an initial version of the --doctor command, which will check various settings of a user's environment and identify possible incompatibilities with delta.

This PR is intended to show a potential pattern for adding new --doctor checks, so I've intentionally kept the list of handled checks short, in anticipation of structural changes that are suggested during code review.

The suggested pattern for adding new checks is to add a new struct that implements the Diagnostic trait, comprised of the following methods:

  • diagnose: gets the setting in the user's environment, and compares it to allowed settings. Returns a Health object with a diagnosis & remedy if the setting is potentially incompatible with delta.
  • remedy: Suggests a remedy, if the Health object returned by diagnose indicates that the setting may be incompatible.
  • report: Reports the value of the setting, whether or not it is "healthy".

Currently, delta --doctor prints the report to stdout.

Addresses #1184.

@clnoll clnoll force-pushed the doctor branch 5 times, most recently from 335a0cc to 3220722 Compare November 15, 2022 23:54
@clnoll clnoll force-pushed the doctor branch 3 times, most recently from 11898ce to 369a044 Compare November 23, 2022 01:14
Comment thread src/subcommands/doctor/less.rs Outdated
impl Diagnostic for Less {
fn report(&self) -> (String, bool) {
match self.version {
Some(n) => match n < self.min_version {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could alternatively use

Some(n) if n < self.min_version

Comment thread src/subcommands/doctor/report.rs Outdated
let mut reports = Vec::new();
for d in diagnostics {
reports.push(build_report_row(d));
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More code golf; I think an alternative here is

    let reports = diagnostics.into_iter().map(build_report_row).collect();

Comment thread src/subcommands/doctor/report.rs Outdated
Ok(())
}

fn build_report_row(diagnostic: Box<dyn Diagnostic>) -> Report {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be named build_report maybe since it returns Report? Or, should it be Report::from_diagnostic()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I went with the Report::from_diagnostic() version.

Comment thread src/subcommands/doctor/report.rs Outdated
use tabled::{Style, Table, Tabled};

#[cfg(not(tarpaulin_include))]
pub fn run_diagnostics() -> std::io::Result<()> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be called print_doctor_report since it's the entrypoint.

@clnoll

clnoll commented Nov 23, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for the review @dandavison! I made the updates you suggested.

@dandavison

Copy link
Copy Markdown
Owner

Rebased on master

@dandavison

Copy link
Copy Markdown
Owner

Another rule possibility: check for installed bat version that would create incompatible assets. Ref #1906

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants