cargo_msrv/sub_command/
show.rs1use camino::Utf8PathBuf;
2use cargo_metadata::MetadataCommand;
3use std::convert::TryFrom;
4
5use crate::context::ShowContext;
6use crate::error::TResult;
7
8use crate::SubCommand;
9use crate::manifest::CargoManifest;
10use crate::reporter::Reporter;
11use crate::reporter::event::ShowResult;
12
13#[derive(Default)]
14pub struct Show;
15
16impl SubCommand for Show {
17 type Context = ShowContext;
18 type Output = ();
19
20 fn run(&self, ctx: &Self::Context, reporter: &impl Reporter) -> TResult<Self::Output> {
21 show_msrv(ctx, reporter)
22 }
23}
24
25fn show_msrv(ctx: &ShowContext, reporter: &impl Reporter) -> TResult<()> {
26 let cargo_toml = ctx.environment.manifest();
29
30 let metadata = MetadataCommand::new().manifest_path(&cargo_toml).exec()?;
31 let manifest = CargoManifest::try_from(metadata)?;
32
33 let msrv = manifest
34 .minimum_rust_version()
35 .ok_or_else(|| Error::NoMSRVInCargoManifest(cargo_toml.to_path_buf()))?;
36
37 reporter.report_event(ShowResult::new(msrv.clone(), cargo_toml.clone()))?;
38
39 Ok(())
40}
41
42#[derive(Debug, thiserror::Error)]
43pub enum Error {
44 #[error("MSRV was not specified in Cargo manifest at '{0}'")]
45 NoMSRVInCargoManifest(Utf8PathBuf),
46}