diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 98c8a464..96534b76 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -105,7 +105,7 @@ pub struct CargoMsrvOpts { #[command(propagate_version = true)] pub enum SubCommand { /// Find & fix MSRV related issues - Doctor, + Doctor(DoctorOpts), /// Find the MSRV Find(FindOpts), /// Display the MSRV's of dependencies @@ -120,6 +120,14 @@ pub enum SubCommand { Verify(VerifyOpts), } +#[derive(Debug, Args)] +#[command(next_help_heading = "Doctor options")] +pub struct DoctorOpts { + /// Try to fix the reported issues + #[arg(long)] + pub fix: bool, +} + // Cli Options for top-level cargo-msrv (find) command #[derive(Debug, Args)] #[command(next_help_heading = "Find MSRV options")] diff --git a/src/context/doctor.rs b/src/context/doctor.rs index 9a76093e..bd89621b 100644 --- a/src/context/doctor.rs +++ b/src/context/doctor.rs @@ -1,9 +1,12 @@ -use crate::cli::CargoMsrvOpts; +use crate::cli::{CargoMsrvOpts, SubCommand}; use crate::context::EnvironmentContext; use crate::error::CargoMSRVError; #[derive(Debug)] pub struct DoctorContext { + /// Try and fix the issues found! + pub fix: bool, + /// Resolved environment options pub environment: EnvironmentContext, } @@ -12,9 +15,19 @@ impl TryFrom for DoctorContext { type Error = CargoMSRVError; fn try_from(opts: CargoMsrvOpts) -> Result { - let CargoMsrvOpts { shared_opts, .. } = opts; + let CargoMsrvOpts { + shared_opts, + subcommand, + .. + } = opts; + + let doctor_opts = match subcommand { + SubCommand::Doctor(opts) => opts, + _ => unreachable!("This should never happen. The subcommand is not `doctor`!"), + }; Ok(Self { + fix: doctor_opts.fix, environment: (&shared_opts).try_into()?, }) } diff --git a/src/context/mod.rs b/src/context/mod.rs index f19a4b06..7ae273e9 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -119,7 +119,7 @@ impl TryFrom for Context { fn try_from(opts: CargoMsrvOpts) -> Result { let ctx = match opts.subcommand { - SubCommand::Doctor => Self::Doctor(DoctorContext::try_from(opts)?), + SubCommand::Doctor(_) => Self::Doctor(DoctorContext::try_from(opts)?), SubCommand::Find(_) => Self::Find(FindContext::try_from(opts)?), SubCommand::List(_) => Self::List(ListContext::try_from(opts)?), SubCommand::Set(_) => Self::Set(SetContext::try_from(opts)?),