Skip to content

Commit

Permalink
Imply --workspace when running in workspace root
Browse files Browse the repository at this point in the history
Aims for saner defaults & to match `cargo update` behavior
  • Loading branch information
Logarithmus committed Nov 11, 2021
1 parent 370c4d0 commit 28ee3f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ supported. Git/path dependencies will be ignored.
All packages in the workspace will be upgraded if the `--workspace` flag is supplied.
The `--workspace` flag may be supplied in the presence of a virtual manifest.
Running in workspace root automatically implies `--workspace`
If the '--to-lockfile' flag is supplied, all dependencies will be upgraded to the currently locked
version as recorded in the Cargo.lock file. This flag requires that the Cargo.lock file is
Expand Down
3 changes: 2 additions & 1 deletion src/bin/set-version/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ fn process(args: Args) -> Result<()> {
if all {
deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?;
}
let all = workspace || all;
let all = workspace || all || LocalManifest::find(&None)?.is_virtual();

let manifests = if all {
Manifests::get_all(&manifest_path)
} else if let Some(ref pkgid) = pkgid {
Expand Down
4 changes: 3 additions & 1 deletion src/bin/upgrade/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct Args {
all: bool,

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

Expand Down Expand Up @@ -468,7 +469,8 @@ fn process(args: Args) -> Result<()> {
deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?;
}

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

if !args.offline && !to_lockfile && std::env::var("CARGO_IS_TEST").is_err() {
let url = registry_url(&find(&manifest_path)?, None)?;
Expand Down
7 changes: 6 additions & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,15 @@ impl LocalManifest {
Ok(LocalManifest { manifest, path })
}

/// Check if local manifest is virtual, i. e. corresponds to workspace root
pub fn is_virtual(&self) -> bool {
!self.data["workspace"].is_none()
}

/// Write changes back to the file
pub fn write(&self) -> Result<()> {
if self.manifest.data["package"].is_none() && self.manifest.data["project"].is_none() {
if !self.manifest.data["workspace"].is_none() {
if self.is_virtual() {
return Err(ErrorKind::UnexpectedRootManifest.into());
} else {
return Err(ErrorKind::InvalidManifest.into());
Expand Down

0 comments on commit 28ee3f7

Please sign in to comment.