Skip to content

Commit

Permalink
chore: Document new add implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 13, 2022
1 parent f1548f6 commit 1a20200
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,14 @@ fn populate_dependency(mut dependency: Dependency, arg: &DepOp) -> Dependency {
dependency
}

/// Track presentation-layer information with the editable representation of a `[dependencies]`
/// entry (Dependency)
pub struct DependencyUI {
/// Editable representation of a `[depednencies]` entry
dep: Dependency,
/// The version of the crate that we pulled `available_features` from
available_version: Option<semver::Version>,
/// The widest set of features compatible with `Dependency`s version requirement
available_features: BTreeMap<String, Vec<String>>,
}

Expand Down Expand Up @@ -772,6 +777,8 @@ fn print_msg(shell: &mut Shell, dep: &DependencyUI, section: &[String]) -> Cargo
let mut version = version.clone();
version.build = Default::default();
let version = version.to_string();
// Avoid displaying the version if it will visually look like the version req that we
// showed earlier
let version_req = dep
.version()
.and_then(|v| semver::VersionReq::parse(v).ok())
Expand Down Expand Up @@ -844,6 +851,8 @@ fn find_workspace_dep(toml_key: &str, root_manifest: &Path) -> CargoResult<Depen
Dependency::from_toml(root_manifest.parent().unwrap(), toml_key, dep_item)
}

/// Convert a `semver::VersionReq` into a rendered `semver::Version` if all fields are fully
/// specified.
fn precise_version(version_req: &semver::VersionReq) -> Option<String> {
version_req
.comparators
Expand Down

0 comments on commit 1a20200

Please sign in to comment.