chiark / gitweb /
misc.online: Support for `auto`
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 19:28:04 +0000 (20:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 19:28:04 +0000 (20:28 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
nailing-cargo

index c108724af7582f0bca2da8b9cbc7aa155db077bd..c4b414727e9794dedcdc265fa98a044254d55bd2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -516,11 +516,16 @@ other names are not looked up in this alias map.
 `[misc]`: Miscellaneous individual nailing-cargo config
 -------------------------------------------------------
 
- * <a name="misc_online">`online`</a>: boolean, specifying whether to
-   pass `--offline` to cargo (cargo's default is online mode).  The
-   default is offline, unless nailing-cargo can see that the cargo
-   subcommand being invoked is one which requires online access, in
-   which case the default is online.
+ * <a name="misc_online">`online`</a>:
+
+   Specifies whether to allow or prevent cargo from accessing the
+   network.  Value is a boolean or `'auto'`.  `'auto'` permits online
+   access if the cargo subcommand being invoked is one whose main
+   purpose involves online access.
+
+   Implemented by passing `--offline` to cargo when necessary ---
+   cargo's default is online.  nailing-cargo's default is
+   `'auto'`.
 
 Limitations and bugs
 ====================
index 9b7be113d20b482d24a2823d42b53723f19617ea..b8428349669c2fccfcbf8c3c17216035241856e6 100755 (executable)
@@ -363,7 +363,23 @@ sub calculate () {
 
 sub addargs () {
   $online = 1 if subcmd_p('online');
-  $online //= cfg_bool qw(misc online);
+  if (!defined $online) {
+    $_ = cfg_uc qw(misc online);
+    if (!defined $_) {
+    } elsif (Types::Serialiser::is_bool $_) {
+      $online = $_;
+    } elsif (ref $_) {
+    } elsif (m/^a/) {
+      $online = undef;
+    } elsif (m/^[1ty]/) { # allow booleanish strings
+      $online = 1;        # for less user frustration
+    } elsif (m/^[0fn]/) {
+      $online = 0;
+    } else {
+      badcfg qw(misc online), "expected boolean or 'auto', found '$_'";
+    }
+  }
+  $online //= cfg_bool 
   $online //= 0;
 
   $cargo_lock_update //= subcmd_p('lock-update');