From 8c01c593d3fe2d59534f86826640d76368937d88 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Thu, 8 Aug 2024 03:00:00 +0200 Subject: [PATCH] Don't pass `OutputFormat` to `Context` anymore It seems the only place where it was actually used was in `src/sub_command/verify.rs`. And even there it was probably not needed since the reporter for 'no output' would most likely discard the message anyway. Not passing the OutputFormat to Context simplifies the code, and is probably also cleaner, since the Context and the commands likely should not care about the output format. The main code will set up reporting according to the output format. --- src/context.rs | 17 +---------------- src/context/find.rs | 5 ----- src/context/list.rs | 6 +----- src/context/set.rs | 6 +----- src/context/show.rs | 6 +----- src/context/verify.rs | 5 ----- src/sub_command/find.rs | 2 -- src/sub_command/find/tests.rs | 6 +----- src/sub_command/verify.rs | 5 +---- src/writer/write_msrv.rs | 22 ++-------------------- 10 files changed, 8 insertions(+), 72 deletions(-) diff --git a/src/context.rs b/src/context.rs index 02b9aac9..800ebe45 100644 --- a/src/context.rs +++ b/src/context.rs @@ -7,7 +7,7 @@ //! Unlike the opts, the context is top down, not bottom up. use crate::cli::rust_releases_opts::RustReleasesOpts; -use crate::cli::shared_opts::{SharedOpts, UserOutputOpts}; +use crate::cli::shared_opts::SharedOpts; use crate::cli::toolchain_opts::ToolchainOpts; use crate::error::{CargoMSRVError, InvalidUtf8Error, IoError, IoErrorSource, PathError}; @@ -296,21 +296,6 @@ impl EnvironmentContext { } } -#[derive(Clone, Debug)] -pub struct UserOutputContext { - /// The output format to use, or `None` if - /// no user output should be presented to the user. - pub output_format: OutputFormat, -} - -impl From for UserOutputContext { - fn from(opts: UserOutputOpts) -> Self { - Self { - output_format: opts.effective_output_format(), - } - } -} - // --- #[derive(Clone, Copy, Debug, Default, PartialEq, ValueEnum)] diff --git a/src/context/find.rs b/src/context/find.rs index 9606104d..5b7cade6 100644 --- a/src/context/find.rs +++ b/src/context/find.rs @@ -2,7 +2,6 @@ use crate::check::RunCommand; use crate::cli::CargoMsrvOpts; use crate::context::{ CheckCommandContext, EnvironmentContext, RustReleasesContext, SearchMethod, ToolchainContext, - UserOutputContext, }; use crate::error::CargoMSRVError; use crate::external_command::cargo_command::CargoCommand; @@ -36,9 +35,6 @@ pub struct FindContext { /// Resolved environment options pub environment: EnvironmentContext, - - /// User output options - pub user_output: UserOutputContext, } impl TryFrom for FindContext { @@ -68,7 +64,6 @@ impl TryFrom for FindContext { toolchain, check_cmd: find_opts.custom_check_opts.into(), environment, - user_output: shared_opts.user_output_opts.into(), }) } } diff --git a/src/context/list.rs b/src/context/list.rs index dbd2ef34..2d6fa177 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -1,5 +1,5 @@ use crate::cli::{CargoMsrvOpts, SubCommand}; -use crate::context::{EnvironmentContext, UserOutputContext}; +use crate::context::EnvironmentContext; use crate::error::CargoMSRVError; use clap::ValueEnum; use std::convert::{TryFrom, TryInto}; @@ -14,9 +14,6 @@ pub struct ListContext { /// Resolved environment options pub environment: EnvironmentContext, - - /// User output options - pub user_output: UserOutputContext, } impl TryFrom for ListContext { @@ -39,7 +36,6 @@ impl TryFrom for ListContext { Ok(Self { variant: subcommand.variant, environment, - user_output: shared_opts.user_output_opts.into(), }) } } diff --git a/src/context/set.rs b/src/context/set.rs index 2c70d48b..12b1148b 100644 --- a/src/context/set.rs +++ b/src/context/set.rs @@ -1,5 +1,5 @@ use crate::cli::{CargoMsrvOpts, SubCommand}; -use crate::context::{EnvironmentContext, RustReleasesContext, UserOutputContext}; +use crate::context::{EnvironmentContext, RustReleasesContext}; use crate::error::CargoMSRVError; use crate::manifest::bare_version::BareVersion; use std::convert::{TryFrom, TryInto}; @@ -14,9 +14,6 @@ pub struct SetContext { /// Resolved environment options pub environment: EnvironmentContext, - - /// User output options - pub user_output: UserOutputContext, } impl TryFrom for SetContext { @@ -41,7 +38,6 @@ impl TryFrom for SetContext { msrv: subcommand.msrv, rust_releases: find_opts.rust_releases_opts.into(), environment, - user_output: shared_opts.user_output_opts.into(), }) } } diff --git a/src/context/show.rs b/src/context/show.rs index 72d1f6ba..d795155e 100644 --- a/src/context/show.rs +++ b/src/context/show.rs @@ -1,5 +1,5 @@ use crate::cli::CargoMsrvOpts; -use crate::context::{EnvironmentContext, UserOutputContext}; +use crate::context::EnvironmentContext; use crate::error::CargoMSRVError; use std::convert::{TryFrom, TryInto}; @@ -7,9 +7,6 @@ use std::convert::{TryFrom, TryInto}; pub struct ShowContext { /// Resolved environment options pub environment: EnvironmentContext, - - /// User output options - pub user_output: UserOutputContext, } impl TryFrom for ShowContext { @@ -20,7 +17,6 @@ impl TryFrom for ShowContext { Ok(Self { environment: (&shared_opts).try_into().unwrap(), // todo! - user_output: shared_opts.user_output_opts.into(), }) } } diff --git a/src/context/verify.rs b/src/context/verify.rs index 09883753..d0860d48 100644 --- a/src/context/verify.rs +++ b/src/context/verify.rs @@ -1,7 +1,6 @@ use crate::cli::{CargoMsrvOpts, SubCommand}; use crate::context::{ CheckCommandContext, EnvironmentContext, RustReleasesContext, ToolchainContext, - UserOutputContext, }; use crate::check::RunCommand; @@ -32,9 +31,6 @@ pub struct VerifyContext { /// Resolved environment options pub environment: EnvironmentContext, - - /// User output options - pub user_output: UserOutputContext, } impl TryFrom for VerifyContext { @@ -68,7 +64,6 @@ impl TryFrom for VerifyContext { toolchain, check_cmd: find_opts.custom_check_opts.into(), environment, - user_output: shared_opts.user_output_opts.into(), }) } } diff --git a/src/sub_command/find.rs b/src/sub_command/find.rs index 41953de8..4f2cf4cf 100644 --- a/src/sub_command/find.rs +++ b/src/sub_command/find.rs @@ -69,7 +69,6 @@ fn find_msrv( if ctx.write_msrv { let environment_ctx = ctx.environment.clone(); - let user_output_ctx = ctx.user_output.clone(); let rust_releases_ctx = ctx.rust_releases.clone(); write_msrv( @@ -77,7 +76,6 @@ fn find_msrv( BareVersion::two_component_from_semver(toolchain.version()), Some(release_index), // Re-use the already obtained index environment_ctx, - user_output_ctx, rust_releases_ctx, )?; } diff --git a/src/sub_command/find/tests.rs b/src/sub_command/find/tests.rs index 6216a5fc..21593446 100644 --- a/src/sub_command/find/tests.rs +++ b/src/sub_command/find/tests.rs @@ -2,11 +2,10 @@ use super::*; use crate::check::TestRunner; use crate::context::{ CheckCommandContext, EnvironmentContext, ReleaseSource, RustReleasesContext, ToolchainContext, - UserOutputContext, }; use crate::manifest::bare_version::BareVersion; use crate::reporter::TestReporterWrapper; -use crate::{Event, OutputFormat}; +use crate::Event; use camino::Utf8PathBuf; use rust_releases::semver; use std::iter::FromIterator; @@ -257,8 +256,5 @@ fn create_test_context() -> FindContext { environment: EnvironmentContext { crate_path: Utf8PathBuf::new(), }, - user_output: UserOutputContext { - output_format: OutputFormat::None, - }, } } diff --git a/src/sub_command/verify.rs b/src/sub_command/verify.rs index 7f9026ae..73f56c73 100644 --- a/src/sub_command/verify.rs +++ b/src/sub_command/verify.rs @@ -5,7 +5,7 @@ use std::convert::TryFrom; use rust_releases::{Release, ReleaseIndex}; use crate::check::Check; -use crate::context::{EnvironmentContext, OutputFormat, VerifyContext}; +use crate::context::{EnvironmentContext, VerifyContext}; use crate::error::{CargoMSRVError, TResult}; use crate::manifest::bare_version::BareVersion; use crate::manifest::CargoManifest; @@ -73,9 +73,6 @@ fn verify_msrv( match runner.check(&toolchain)? { Outcome::Success(_) => success(reporter, toolchain), - Outcome::Failure(_) if ctx.user_output.output_format == OutputFormat::None => { - failure(reporter, toolchain, rust_version, None) - } Outcome::Failure(f) => failure(reporter, toolchain, rust_version, Some(f.error_message)), } } diff --git a/src/writer/write_msrv.rs b/src/writer/write_msrv.rs index b565b86a..539bdbcc 100644 --- a/src/writer/write_msrv.rs +++ b/src/writer/write_msrv.rs @@ -1,4 +1,4 @@ -use crate::context::{EnvironmentContext, RustReleasesContext, SetContext, UserOutputContext}; +use crate::context::{EnvironmentContext, RustReleasesContext, SetContext}; use crate::manifest::bare_version::BareVersion; use crate::reporter::Reporter; use crate::{Set, SubCommand, TResult}; @@ -12,13 +12,11 @@ pub fn write_msrv( msrv: BareVersion, release_index: Option<&ReleaseIndex>, environment: EnvironmentContext, - user_output: UserOutputContext, rust_releases: RustReleasesContext, ) -> TResult<()> { let context = SetContext { msrv, environment, - user_output, rust_releases, }; @@ -29,12 +27,11 @@ pub fn write_msrv( #[cfg(test)] mod tests { - use crate::context::{EnvironmentContext, RustReleasesContext, UserOutputContext}; + use crate::context::{EnvironmentContext, RustReleasesContext}; use crate::error::CargoMSRVError; use crate::manifest::bare_version::BareVersion; use crate::reporter::FakeTestReporter; use crate::writer::write_msrv::write_msrv; - use crate::OutputFormat; use camino::Utf8Path; use rust_releases::{semver, ReleaseIndex}; use std::iter::FromIterator; @@ -56,10 +53,6 @@ mod tests { crate_path: root.to_path_buf(), }; - let user_output = UserOutputContext { - output_format: OutputFormat::None, - }; - let index = ReleaseIndex::from_iter(vec![rust_releases::Release::new_stable( semver::Version::new(2, 0, 5), )]); @@ -69,7 +62,6 @@ mod tests { version, Some(&index), env, - user_output, RustReleasesContext::default(), ) .unwrap(); @@ -94,10 +86,6 @@ mod tests { crate_path: root.to_path_buf(), }; - let user_output = UserOutputContext { - output_format: OutputFormat::None, - }; - let index = ReleaseIndex::from_iter(vec![]); let err = write_msrv( @@ -105,7 +93,6 @@ mod tests { version, Some(&index), env, - user_output, RustReleasesContext::default(), ) .unwrap_err(); @@ -129,16 +116,11 @@ mod tests { crate_path: root.to_path_buf(), }; - let user_output = UserOutputContext { - output_format: OutputFormat::None, - }; - write_msrv( &fake_reporter, version, None, env, - user_output, RustReleasesContext::default(), ) .unwrap();