]> git.proxmox.com Git - cargo.git/commitdiff
add `--dry-run` option to cargo update
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 2 Dec 2018 11:41:16 +0000 (14:41 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 8 Dec 2018 18:25:56 +0000 (21:25 +0300)
src/bin/cargo/commands/publish.rs
src/bin/cargo/commands/update.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/util/command_prelude.rs

index b2eb7abb00f6f573d6779734a88d120fa2706c51..69845d033da413969873208d2e5b215c0e3d1357 100644 (file)
@@ -19,7 +19,7 @@ pub fn cli() -> App {
         .arg_target_dir()
         .arg_manifest_path()
         .arg_jobs()
-        .arg(opt("dry-run", "Perform all checks without uploading"))
+        .arg_dry_run("Perform all checks without uploading")
         .arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
 }
 
index 766226d0f24db8e18928f0e35bd033896bf32ec4..246aab8867bc1518827df6b7abb0f84b16fa822b 100644 (file)
@@ -10,6 +10,7 @@ pub fn cli() -> App {
             "aggressive",
             "Force updating all dependencies of <name> as well",
         ))
+        .arg_dry_run("Don't actually write the lockfile")
         .arg(opt("precise", "Update a single dependency to exactly PRECISE").value_name("PRECISE"))
         .arg_manifest_path()
         .after_help(
@@ -44,6 +45,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
         aggressive: args.is_present("aggressive"),
         precise: args.value_of("precise"),
         to_update: values(args, "package"),
+        dry_run: args.is_present("dry-run"),
         config,
     };
     ops::update_lockfile(&ws, &update_opts)?;
index d62c133d412c210b68daff6c567368df2a090367..0881667e1986f65fc55b03b1aa357bb1d1fe0bd5 100644 (file)
@@ -15,6 +15,7 @@ pub struct UpdateOptions<'a> {
     pub to_update: Vec<String>,
     pub precise: Option<&'a str>,
     pub aggressive: bool,
+    pub dry_run: bool,
 }
 
 pub fn generate_lockfile(ws: &Workspace) -> CargoResult<()> {
@@ -118,8 +119,13 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions) -> CargoResult<()>
             }
         }
     }
-
-    ops::write_pkg_lockfile(ws, &resolve)?;
+    if opts.dry_run {
+        opts.config
+            .shell()
+            .warn("not updating lockfile due to dry run")?;
+    } else {
+        ops::write_pkg_lockfile(ws, &resolve)?;
+    }
     return Ok(());
 
     fn fill_with_deps<'a>(
index 1985cd575ed58f414d4a6bb796389e0d881cbe1f..4bc0f0a6c91925f265a8a7a75bc6d8abb25d7672 100644 (file)
@@ -177,6 +177,10 @@ pub trait AppExt: Sized {
                     .hidden(true),
             )
     }
+
+    fn arg_dry_run(self, dry_run: &'static str) -> Self {
+        self._arg(opt("dry-run", dry_run))
+    }
 }
 
 impl AppExt for App {