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

Don't pass OutputFormat to Context anymore #971

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<UserOutputOpts> for UserOutputContext {
fn from(opts: UserOutputOpts) -> Self {
Self {
output_format: opts.effective_output_format(),
}
}
}

// ---

#[derive(Clone, Copy, Debug, Default, PartialEq, ValueEnum)]
Expand Down
5 changes: 0 additions & 5 deletions src/context/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,9 +35,6 @@ pub struct FindContext {

/// Resolved environment options
pub environment: EnvironmentContext,

/// User output options
pub user_output: UserOutputContext,
}

impl TryFrom<CargoMsrvOpts> for FindContext {
Expand Down Expand Up @@ -68,7 +64,6 @@ impl TryFrom<CargoMsrvOpts> for FindContext {
toolchain,
check_cmd: find_opts.custom_check_opts.into(),
environment,
user_output: shared_opts.user_output_opts.into(),
})
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/context/list.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -14,9 +14,6 @@ pub struct ListContext {

/// Resolved environment options
pub environment: EnvironmentContext,

/// User output options
pub user_output: UserOutputContext,
}

impl TryFrom<CargoMsrvOpts> for ListContext {
Expand All @@ -39,7 +36,6 @@ impl TryFrom<CargoMsrvOpts> for ListContext {
Ok(Self {
variant: subcommand.variant,
environment,
user_output: shared_opts.user_output_opts.into(),
})
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/context/set.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -14,9 +14,6 @@ pub struct SetContext {

/// Resolved environment options
pub environment: EnvironmentContext,

/// User output options
pub user_output: UserOutputContext,
}

impl TryFrom<CargoMsrvOpts> for SetContext {
Expand All @@ -41,7 +38,6 @@ impl TryFrom<CargoMsrvOpts> for SetContext {
msrv: subcommand.msrv,
rust_releases: find_opts.rust_releases_opts.into(),
environment,
user_output: shared_opts.user_output_opts.into(),
})
}
}
6 changes: 1 addition & 5 deletions src/context/show.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::cli::CargoMsrvOpts;
use crate::context::{EnvironmentContext, UserOutputContext};
use crate::context::EnvironmentContext;
use crate::error::CargoMSRVError;
use std::convert::{TryFrom, TryInto};

#[derive(Debug)]
pub struct ShowContext {
/// Resolved environment options
pub environment: EnvironmentContext,

/// User output options
pub user_output: UserOutputContext,
}

impl TryFrom<CargoMsrvOpts> for ShowContext {
Expand All @@ -20,7 +17,6 @@ impl TryFrom<CargoMsrvOpts> for ShowContext {

Ok(Self {
environment: (&shared_opts).try_into().unwrap(), // todo!
user_output: shared_opts.user_output_opts.into(),
})
}
}
5 changes: 0 additions & 5 deletions src/context/verify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::cli::{CargoMsrvOpts, SubCommand};
use crate::context::{
CheckCommandContext, EnvironmentContext, RustReleasesContext, ToolchainContext,
UserOutputContext,
};

use crate::check::RunCommand;
Expand Down Expand Up @@ -32,9 +31,6 @@ pub struct VerifyContext {

/// Resolved environment options
pub environment: EnvironmentContext,

/// User output options
pub user_output: UserOutputContext,
}

impl TryFrom<CargoMsrvOpts> for VerifyContext {
Expand Down Expand Up @@ -68,7 +64,6 @@ impl TryFrom<CargoMsrvOpts> for VerifyContext {
toolchain,
check_cmd: find_opts.custom_check_opts.into(),
environment,
user_output: shared_opts.user_output_opts.into(),
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/sub_command/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ 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(
reporter,
BareVersion::two_component_from_semver(toolchain.version()),
Some(release_index), // Re-use the already obtained index
environment_ctx,
user_output_ctx,
rust_releases_ctx,
)?;
}
Expand Down
6 changes: 1 addition & 5 deletions src/sub_command/find/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -257,8 +256,5 @@ fn create_test_context() -> FindContext {
environment: EnvironmentContext {
crate_path: Utf8PathBuf::new(),
},
user_output: UserOutputContext {
output_format: OutputFormat::None,
},
}
}
5 changes: 1 addition & 4 deletions src/sub_command/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
}
}
Expand Down
22 changes: 2 additions & 20 deletions src/writer/write_msrv.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
};

Expand All @@ -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;
Expand All @@ -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),
)]);
Expand All @@ -69,7 +62,6 @@ mod tests {
version,
Some(&index),
env,
user_output,
RustReleasesContext::default(),
)
.unwrap();
Expand All @@ -94,18 +86,13 @@ 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(
&fake_reporter,
version,
Some(&index),
env,
user_output,
RustReleasesContext::default(),
)
.unwrap_err();
Expand All @@ -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();
Expand Down
Loading