From 5346159fc43651eb4c59eb50977495294cc6c4fa Mon Sep 17 00:00:00 2001 From: Cassaundra Smith Date: Tue, 6 Sep 2022 14:46:38 -0700 Subject: [PATCH] Expose cargo add internals as utils Move cargo add utils out for future use by other subcommands (namely cargo remove, per #10520). --- src/bin/cargo/commands/add.rs | 2 +- src/cargo/ops/cargo_add/crate_spec.rs | 2 +- src/cargo/ops/cargo_add/mod.rs | 20 ++++++++----------- .../ops/{cargo_add => edit}/dependency.rs | 2 +- src/cargo/ops/{cargo_add => edit}/manifest.rs | 0 src/cargo/ops/edit/mod.rs | 4 ++++ src/cargo/ops/mod.rs | 1 + 7 files changed, 16 insertions(+), 15 deletions(-) rename src/cargo/ops/{cargo_add => edit}/dependency.rs (99%) rename src/cargo/ops/{cargo_add => edit}/manifest.rs (100%) create mode 100644 src/cargo/ops/edit/mod.rs diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs index 1ff2aad1944d..2f1e1564ab57 100644 --- a/src/bin/cargo/commands/add.rs +++ b/src/bin/cargo/commands/add.rs @@ -6,7 +6,7 @@ use cargo::core::FeatureValue; use cargo::ops::cargo_add::add; use cargo::ops::cargo_add::AddOptions; use cargo::ops::cargo_add::DepOp; -use cargo::ops::cargo_add::DepTable; +use cargo::ops::edit::manifest::DepTable; use cargo::ops::resolve_ws; use cargo::util::command_prelude::*; use cargo::util::interning::InternedString; diff --git a/src/cargo/ops/cargo_add/crate_spec.rs b/src/cargo/ops/cargo_add/crate_spec.rs index 33b4957f7587..96d56a18685b 100644 --- a/src/cargo/ops/cargo_add/crate_spec.rs +++ b/src/cargo/ops/cargo_add/crate_spec.rs @@ -3,7 +3,7 @@ use anyhow::Context as _; use super::Dependency; -use super::RegistrySource; +use crate::ops::edit::dependency::RegistrySource; use crate::util::validate_package_name; use crate::CargoResult; diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index c584a03f8584..d38191fc4eb1 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -1,9 +1,6 @@ //! Core of cargo-add command mod crate_spec; -mod dependency; -mod manifest; - use anyhow::Context; use std::collections::BTreeSet; use std::collections::VecDeque; @@ -23,18 +20,17 @@ use crate::core::QueryKind; use crate::core::Registry; use crate::core::Shell; use crate::core::Workspace; +use crate::ops::edit::dependency::Dependency; +use crate::ops::edit::dependency::GitSource; +use crate::ops::edit::dependency::MaybeWorkspace; +use crate::ops::edit::dependency::PathSource; +use crate::ops::edit::dependency::Source; +use crate::ops::edit::dependency::WorkspaceSource; +use crate::ops::edit::manifest::DepTable; +use crate::ops::edit::manifest::LocalManifest; use crate::CargoResult; use crate::Config; use crate_spec::CrateSpec; -use dependency::Dependency; -use dependency::GitSource; -use dependency::PathSource; -use dependency::RegistrySource; -use dependency::Source; -use manifest::LocalManifest; - -use crate::ops::cargo_add::dependency::{MaybeWorkspace, WorkspaceSource}; -pub use manifest::DepTable; /// Information on what dependencies should be added #[derive(Clone, Debug)] diff --git a/src/cargo/ops/cargo_add/dependency.rs b/src/cargo/ops/edit/dependency.rs similarity index 99% rename from src/cargo/ops/cargo_add/dependency.rs rename to src/cargo/ops/edit/dependency.rs index e86f12e033c1..39adba776e49 100644 --- a/src/cargo/ops/cargo_add/dependency.rs +++ b/src/cargo/ops/edit/dependency.rs @@ -938,7 +938,7 @@ impl Display for WorkspaceSource { mod tests { use std::path::Path; - use crate::ops::cargo_add::manifest::LocalManifest; + use crate::ops::edit::manifest::LocalManifest; use cargo_util::paths; use super::*; diff --git a/src/cargo/ops/cargo_add/manifest.rs b/src/cargo/ops/edit/manifest.rs similarity index 100% rename from src/cargo/ops/cargo_add/manifest.rs rename to src/cargo/ops/edit/manifest.rs diff --git a/src/cargo/ops/edit/mod.rs b/src/cargo/ops/edit/mod.rs new file mode 100644 index 000000000000..76ea2f094f72 --- /dev/null +++ b/src/cargo/ops/edit/mod.rs @@ -0,0 +1,4 @@ +//! Utilities for editing Cargo.toml manifests + +pub mod dependency; +pub mod manifest; diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index a5715c13ec3c..9c2b37028f4a 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -49,6 +49,7 @@ mod cargo_run; mod cargo_test; mod cargo_uninstall; mod common_for_install_and_uninstall; +pub mod edit; mod fix; mod lockfile; mod registry;