chiark / gitweb /
New --force, and make lack of -E fail by default
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 21 Jun 2021 11:58:41 +0000 (12:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 21 Jun 2021 12:02:17 +0000 (13:02 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
nailing-cargo

index b87350dfadc61806ab919d2b5506e16b17cff23f..124d352317c47e98b9bc81b48137661f3a021c77 100644 (file)
--- a/README.md
+++ b/README.md
@@ -280,6 +280,9 @@ Options
   * `-n`: "No action": stop after writing `Cargo.toml.nailing~`
        everywhere, and do not run any build command.
 
+  * `-f` | `--force`: Force going ahead even if problems are likely.
+    (E.g., due to missing `-E` option.)
+
   * `-T<arch>` | `--target=<arch>`
 
     Specify target architecture.
@@ -367,8 +370,8 @@ WASM="wasm32-unknown-unknown"
 
     * `lock_update`: cargo will want to update `Cargo.lock`.  (The `-u` and `-U` options override this.)
     * `online`: this subcommand makes no sense to run offline.  (The `-o` and `-O` options, and the configuration, can override this.)
-    * `edits`: The purpose of this subcommand is to edit the source tree.  Produces warning if `--edit-sources` mode not specified.
-    * `creates`: The purpose of this subcommand is to edit the source tree and create new files in it.  Produces warning if `--edit-sources` (`-E`) mode not specified twice.
+    * `edits`: The purpose of this subcommand is to edit the source tree.  Imples that `--edit-sources` is necessary (unless `--force`).
+    * `creates`: The purpose of this subcommand is to edit the source tree and create new files in it.  Imples that `-EE` (`--edit-sources`, twice) is necessary (unless `--force`).
     * `!target`: cargo would reject `--target=<arch>`; in this case nailing-cargo's `-T` option is ineffective.
     * `!target-dir`: cargo would reject `--target-dir`, so don't pass it.  (Usually we pass `--target-dir=target` when we pass `--manifest-path`, since cargo's default is `target` in the same directory as `Cargo.toml`.)
     * `linkfarm-shallow`: Make the default be `--linkfarm=shallow`.  This is the default for `miri` and can also be used for other subcommands which do not understandg `--manifest-path` properly.
@@ -428,7 +431,8 @@ WASM="wasm32-unknown-unknown"
     should use git to review the edits made by the cargo command and
     either stage and commit them, or reject them.
 
-    This is the default mode for `nailing-cargo fmt`.
+    `-E` or `-f` is needed for `nailing-cargo fmt`.  `-EE` or `-f` is
+    needed for `nailing-cargo init`.  (`-E` is never the default.)
 
   * `--just-linkfarm[=shallow|git|full]`: Make the out-of-tree
     linkfarm as if for `--cargo-lock-update`, but do not actually run
index 220222abcf04c5abbf71c72d544e7f37a6d17525..240a5a058b8c176e79a8591c5c330d93ce465b1f 100755 (executable)
@@ -28,6 +28,7 @@ options:
   --doc --man --manual            Display complete manual (in w3m)
   --leave-nailed                  Leave the nailed Cargo.toml in place
   -E | --edits-sources            Allow source edits (repeat: file creation)
+  -f | --force                    Override some warnings
   --linkfarm[=no|shallow|git|full]        (default varies, usually "no")
   --just-linkfarm | --clean-linkfarm | --keep-linkfarm (default is keep)
   --[no-]preclean-build[=no|src|full]               (default is no)
@@ -121,6 +122,8 @@ our @subcmd_xprops = qw(!manifest-path);
 
 our @configs;
 our $verbose=1;
+our $force=0;
+our $forced=0;
 our ($noact,$dump);
 our $target;
 
@@ -136,6 +139,17 @@ sub show_manual () {
   die "$self: exec sh failed: $!";
 }
 
+sub forceable_warning ($) {
+  my ($m) = @_;
+  print STDERR "$self: *WARNING*: $m\n";
+  if ($force) {
+    print STDERR "$self: continuing because of --force...\n" unless $forced++;
+    return;
+  } else {
+    die "$self: Stopping due to warning (override with -f | --force)\n";
+  }
+}
+
 sub read_or_enoent ($) {
   my ($fn) = @_;
   if (!open R, '<', $fn) {
@@ -581,8 +595,8 @@ sub addargs () {
   if ($linkfarm_depth eq 'copy-edit-all') {
     $oot_preclean //= 'src';
     if ($oot_preclean !~ m/^(?:src|full)$/) {
-      print STDERR
- "$self: *WARNING*: -EE specified, but also --preclean=no; will probably leave your source tree full of junk\n";
+      forceable_warning
+ "-EE specified, but also --preclean=no; will probably leave your source tree full of junk";
     }
   }
 
@@ -623,11 +637,11 @@ sub addargs () {
   push @add, "--offline" unless $online || subcmd_p('!offline');
 
   if (subcmd_p('creates') && $linkfarm_depth !~ m/^copy-edit-all/) {
-    print STDERR
- "$self: *WARNING*: this subcommand expects to create new source files; you probably want to specify --edits-sources twice aka -EE (which is not the default even now, for safety reasons)\n";
+    forceable_warning
+ "this subcommand expects to create new source files; you probably want to specify --edits-sources twice aka -EE (which is not the default even now, for safety reasons)";
   } elsif (subcmd_p('edits') && $linkfarm_depth !~ m/^copy-edit/) {
-    print STDERR
- "$self: *WARNING*: this subcommand expects to edit the source code; you probably want to specify --edits-sources aka -E (which is not the default even now, for safety reasons)\n";
+    forceable_warning
+ "this subcommand expects to edit the source code; you probably want to specify --edits-sources aka -E (which is not the default even now, for safety reasons)";
   }
 
   push @args_preface, @add if $pass_options;
@@ -1047,6 +1061,8 @@ sub parse_args () {
          $verbose=0;
        } elsif (s{^-n}{-}) {
          $noact++;
+       } elsif (s{^-f}{-}) {
+         $force++;
        } elsif (s{^-s(.+)}{-}s) {
          $cargo_subcmd = $1;
        } elsif (s{^-([uU])}{-}) {
@@ -1082,6 +1098,8 @@ sub parse_args () {
       $linkfarm_depth = $1 || 'git';
     } elsif (m{^--edits?-sources?$}) {
       $edits_sources->();
+    } elsif (m{^--force$}) {
+      $force++;
     } elsif (m{^--just-run$}) {
       $do_nail = $do_cargo_lock = $do_lock = 0;
     } elsif (m{^--(clean|keep)-linkfarm$}) {
@@ -1173,7 +1191,9 @@ if ($dump) {
                           oot_absdir => $oot_absdir,
                           build_absdir => $build_absdir,
                           linkfarm_depth => $linkfarm_depth,
-                          oot_preclean => $oot_preclean, });
+                          oot_preclean => $oot_preclean,
+                          force => $force,,
+                          forced => $forced,});
   ' or die $@;
 }