Skip to content

Commit

Permalink
Add fix flag to doctor subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
foresterre committed Nov 11, 2024
1 parent 56ba326 commit 94624ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")]
Expand Down
17 changes: 15 additions & 2 deletions src/context/doctor.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand All @@ -12,9 +15,19 @@ impl TryFrom<CargoMsrvOpts> for DoctorContext {
type Error = CargoMSRVError;

fn try_from(opts: CargoMsrvOpts) -> Result<Self, Self::Error> {
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()?,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TryFrom<CargoMsrvOpts> for Context {

fn try_from(opts: CargoMsrvOpts) -> Result<Self, Self::Error> {
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)?),
Expand Down

0 comments on commit 94624ea

Please sign in to comment.