Skip to content

Commit

Permalink
Add --workspace and friends to cargo-msrv cli
Browse files Browse the repository at this point in the history
  • Loading branch information
foresterre committed Oct 14, 2024
1 parent f1d7ca7 commit 690a91e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bisector = "0.4.0" # bisection with a custom comparator
camino = "1.1" # utf-8 paths
cargo_metadata = "0.18.1" # resolving Cargo manifest metadata (consider `guppy`!)
clap = { version = "4.5.20", features = ["derive"] } # parse CLI arguments
clap-cargo = { version = "0.14.1", features = ["cargo_metadata"] }
dirs = "5.0.1" # common directories
indicatif = "0.17.8" # UI
once_cell = "1.20.2" # lazy data structures and thunking
Expand Down
3 changes: 3 additions & 0 deletions src/cli/shared_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct SharedOpts {
#[arg(long, value_name = "Cargo Manifest", global = true, value_hint = ValueHint::FilePath)]
pub manifest_path: Option<PathBuf>,

#[command(flatten)]
pub workspace: clap_cargo::Workspace,

#[command(flatten)]
pub user_output_opts: UserOutputOpts,

Expand Down
27 changes: 26 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ pub struct EnvironmentContext {
/// Does not include a manifest file like Cargo.toml, so it's easy to append
/// a file path like `Cargo.toml` or `Cargo.lock`.
pub crate_path: Utf8PathBuf,

/// Resolved workspace
pub workspace_packages: WorkspacePackages,
}

impl<'shared_opts> TryFrom<&'shared_opts SharedOpts> for EnvironmentContext {
Expand Down Expand Up @@ -275,7 +278,16 @@ impl<'shared_opts> TryFrom<&'shared_opts SharedOpts> for EnvironmentContext {
CargoMSRVError::Path(PathError::InvalidUtf8(InvalidUtf8Error::from(err)))
})?;

Ok(Self { crate_path })
let metadata = cargo_metadata::MetadataCommand::new()
.manifest_path(&crate_path)
.exec()?;
let workspace = opts.workspace.partition_packages(&metadata);
let workspace_packages = WorkspacePackages::from_iter(workspace.0.into_iter().cloned());

Ok(Self {
crate_path,
workspace_packages,
})
}
}

Expand All @@ -298,6 +310,19 @@ impl EnvironmentContext {

// ---

#[derive(Clone, Debug)]
pub struct WorkspacePackages {
_selected: Vec<cargo_metadata::Package>,
}

impl WorkspacePackages {
pub fn from_iter(selected: impl IntoIterator<Item = cargo_metadata::Package>) -> Self {
Self {
_selected: selected.into_iter().collect(),
}
}
}

#[derive(Clone, Copy, Debug, Default, PartialEq, ValueEnum)]
pub enum OutputFormat {
/// Progress bar rendered to stderr
Expand Down

0 comments on commit 690a91e

Please sign in to comment.