Skip to content

Commit

Permalink
Teach publish the --dry-run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAPerson committed Jun 9, 2015
1 parent 1ae683a commit 0686fb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct Options {
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_no_verify: bool,
flag_dry_run: bool,
}

pub const USAGE: &'static str = "
Expand All @@ -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
";
Expand All @@ -34,11 +36,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
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)
})
}
15 changes: 13 additions & 2 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ pub fn publish(manifest_path: &Path,
config: &Config,
token: Option<String>,
index: Option<String>,
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());
Expand All @@ -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(())
}
Expand Down

0 comments on commit 0686fb0

Please sign in to comment.