From 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Mon Sep 17 00:00:00 2001 From: Jason Priest Date: Tue, 9 Jun 2015 14:38:58 -0500 Subject: [PATCH] Teach publish the `--dry-run` flag Closes #1332 --- src/bin/publish.rs | 6 +++++- src/cargo/ops/registry.rs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/bin/publish.rs b/src/bin/publish.rs index 224c9a8b656..49dc741e098 100644 --- a/src/bin/publish.rs +++ b/src/bin/publish.rs @@ -9,6 +9,7 @@ struct Options { flag_manifest_path: Option, flag_verbose: bool, flag_no_verify: bool, + flag_dry_run: bool, } pub const USAGE: &'static str = " @@ -23,6 +24,7 @@ Options: --token TOKEN Token to use when uploading --no-verify Don't verify package tarball before publish --manifest-path PATH Path to the manifest to compile + --dry-run Performs all checks without uploading -v, --verbose Use verbose output "; @@ -34,11 +36,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { flag_host: host, flag_manifest_path, flag_no_verify: no_verify, + flag_dry_run: dry, .. } = options; let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone())); - ops::publish(&root, config, token, host, !no_verify).map(|_| None).map_err(|err| { + ops::publish(&root, config, token, host, + !no_verify, dry).map(|_| None).map_err(|err| { CliError::from_boxed(err, 101) }) } diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 7bd22b3606b..89c9ed020a4 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -30,7 +30,13 @@ pub fn publish(manifest_path: &Path, config: &Config, token: Option, index: Option, - verify: bool) -> CargoResult<()> { + verify: bool, + dry: bool) -> CargoResult<()> { + if !verify && dry { + return Err(human("cannot specify both no verify and dry run \ + simultaneously")) + } + let mut src = try!(PathSource::for_path(manifest_path.parent().unwrap(), config)); try!(src.update()); @@ -45,8 +51,13 @@ pub fn publish(manifest_path: &Path, false, true)).unwrap(); // Upload said tarball to the specified destination + // However, do not upload if performing a dry run try!(config.shell().status("Uploading", pkg.package_id().to_string())); - try!(transmit(&pkg, &tarball, &mut registry)); + if !dry { + try!(transmit(&pkg, &tarball, &mut registry)); + } else { + try!(config.shell().warn("Aborting upload due to dry run")); + } Ok(()) }