Skip to content

Commit 9be95df

Browse files
committed
feat: Add hint for adding members to workspace
1 parent bb9b25f commit 9be95df

File tree

9 files changed

+27
-5
lines changed

9 files changed

+27
-5
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,24 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
844844
}
845845

846846
// Try to add the new package to the workspace members.
847-
update_manifest_with_new_member(
847+
if update_manifest_with_new_member(
848848
&root_manifest_path,
849849
&mut workspace_document,
850850
&display_path,
851-
)?;
851+
)? {
852+
config.shell().status(
853+
"Adding",
854+
format!(
855+
"`{}` as member of workspace at `{}`",
856+
PathBuf::from(&display_path)
857+
.file_name()
858+
.unwrap()
859+
.to_str()
860+
.unwrap(),
861+
root_manifest_path.parent().unwrap().display()
862+
),
863+
)?
864+
}
852865
}
853866
}
854867
}
@@ -965,7 +978,7 @@ fn update_manifest_with_new_member(
965978
root_manifest_path: &Path,
966979
workspace_document: &mut toml_edit::Document,
967980
display_path: &str,
968-
) -> CargoResult<()> {
981+
) -> CargoResult<bool> {
969982
// If the members element already exist, check if one of the patterns
970983
// in the array already includes the new package's relative path.
971984
// - Add the relative path if the members don't match the new package's path.
@@ -983,7 +996,7 @@ fn update_manifest_with_new_member(
983996
.with_context(|| format!("cannot build glob pattern from `{}`", pat))?;
984997

985998
if pattern.matches(&display_path) {
986-
return Ok(());
999+
return Ok(false);
9871000
}
9881001
}
9891002

@@ -1003,7 +1016,8 @@ fn update_manifest_with_new_member(
10031016
write_atomic(
10041017
&root_manifest_path,
10051018
workspace_document.to_string().to_string().as_bytes(),
1006-
)
1019+
)?;
1020+
Ok(true)
10071021
}
10081022

10091023
fn get_display_path(root_manifest_path: &Path, package_path: &Path) -> CargoResult<String> {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating binary (application) package
2+
Adding `foo` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating library `bar` package
2+
Adding `bar` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating binary (application) `foo` package
2+
Adding `foo` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating binary (application) `foo` package
2+
Adding `foo` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating binary (application) `foo` package
2+
Adding `foo` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating binary (application) `foo` package
2+
Adding `foo` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Creating library `bar` package
2+
Adding `bar` as member of workspace at `[ROOT]/case`
23
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

tests/testsuite/workspaces.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ fn new_creates_members_list() {
10651065
p.cargo("new --lib bar")
10661066
.with_stderr("\
10671067
[CREATING] library `bar` package
1068+
[ADDING] `bar` as member of workspace at `[ROOT]/foo`
10681069
[NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10691070
")
10701071
.run();

0 commit comments

Comments
 (0)