Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

clnoll
Copy link
Contributor

@clnoll clnoll commented Sep 15, 2022

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.

impl Diagnostic for Less {
fn report(&self) -> (String, bool) {
match self.version {
Some(n) => match n < self.min_version {
Copy link
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

let mut reports = Vec::new();
for d in diagnostics {
reports.push(build_report_row(d));
}
Copy link
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();

Ok(())
}

fn build_report_row(diagnostic: Box<dyn Diagnostic>) -> Report {
Copy link
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
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.

use tabled::{Style, Table, Tabled};

#[cfg(not(tarpaulin_include))]
pub fn run_diagnostics() -> std::io::Result<()> {
Copy link
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
Copy link
Contributor Author

clnoll commented Nov 23, 2022

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

@dandavison
Copy link
Owner

Rebased on master

@dandavison
Copy link
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