Skip to content

Commit 26a2985

Browse files
committed
Imply --workspace when running in workspace root
Aims for saner defaults & to match `cargo update` behavior
1 parent 370c4d0 commit 26a2985

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ supported. Git/path dependencies will be ignored.
236236
237237
All packages in the workspace will be upgraded if the `--workspace` flag is supplied.
238238
The `--workspace` flag may be supplied in the presence of a virtual manifest.
239+
Running in workspace root automatically implies `--workspace`
239240
240241
If the '--to-lockfile' flag is supplied, all dependencies will be upgraded to the currently locked
241242
version as recorded in the Cargo.lock file. This flag requires that the Cargo.lock file is

src/bin/set-version/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ fn process(args: Args) -> Result<()> {
7575
if all {
7676
deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?;
7777
}
78-
let all = workspace || all;
78+
let all = workspace || all || LocalManifest::find(&None)?.is_virtual();
79+
7980
let manifests = if all {
8081
Manifests::get_all(&manifest_path)
8182
} else if let Some(ref pkgid) = pkgid {

src/bin/upgrade/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct Args {
9494
all: bool,
9595

9696
/// Upgrade all packages in the workspace.
97+
/// Implied by default when running in a directory with virtual manifest.
9798
#[structopt(long = "workspace", conflicts_with = "all", conflicts_with = "pkgid")]
9899
workspace: bool,
99100

@@ -211,6 +212,7 @@ impl Manifests {
211212
}
212213
let result = cmd.exec().chain_err(|| "Invalid manifest")?;
213214
let packages = result.packages;
215+
dbg!(&packages);
214216
let package = packages
215217
.iter()
216218
.find(|p| p.manifest_path == resolved_manifest_path)
@@ -468,7 +470,8 @@ fn process(args: Args) -> Result<()> {
468470
deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?;
469471
}
470472

471-
let all = workspace || all;
473+
// Running in workspace root automatically implies `--workspace`
474+
let all = workspace || all || LocalManifest::find(&None)?.is_virtual();
472475

473476
if !args.offline && !to_lockfile && std::env::var("CARGO_IS_TEST").is_err() {
474477
let url = registry_url(&find(&manifest_path)?, None)?;

src/manifest.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,15 @@ impl LocalManifest {
293293
Ok(LocalManifest { manifest, path })
294294
}
295295

296+
/// Check if local manifest is virtual, i. e. corresponds to workspace root
297+
pub fn is_virtual(&self) -> bool {
298+
!self.data["workspace"].is_none()
299+
}
300+
296301
/// Write changes back to the file
297302
pub fn write(&self) -> Result<()> {
298303
if self.manifest.data["package"].is_none() && self.manifest.data["project"].is_none() {
299-
if !self.manifest.data["workspace"].is_none() {
304+
if self.is_virtual() {
300305
return Err(ErrorKind::UnexpectedRootManifest.into());
301306
} else {
302307
return Err(ErrorKind::InvalidManifest.into());

0 commit comments

Comments
 (0)