chiark / gitweb /
config: Substitutions prefer %{...} to %(...)s, document, etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 18:38:06 +0000 (19:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 19:47:28 +0000 (20:47 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.config
src/config.rs

index cde9e130d248f5e183338d3e76960ca4839e16f8..cc921c1ceef71ce188b834957eaafc62f715128f 100644 (file)
@@ -71,11 +71,13 @@ Exceptional settings:
      Command to run to create and communicate with local network
      interface.  Passed to sh -c.  Must speak SLIP on stdin/stdout.
      The following interpolations aare substituted:
-                       %(local)s  %(peer)s  %(rnets)s   %(ifname)s
+                       %{local}   %{peer}   %{rnets}    %{ifname}
           on server    <vaddr>    <vrelay>  <vnetwork>  <ifname_server>
           on client    <client>   <vaddr>   <vroutes>   <ifname_client>
-     Plus %(mtu)s (and %% to indicate a literal %).
-     ["userv root ipif %(local)s,%(peer)s,%(mtu)s,slip '%(rnets)s'"]
+     Plus %{mtu} and %% to indicate a literal %.
+     (For compatibility with older hippotat, %(var)s is supported too
+     but this is deprecated since the extra `s` is confusing.)
+     ["userv root ipif %{local},%{peer},%{mtu},slip '%{rnets}'"]
 
      On server: applies to all clients; not looked up in
       client-specific sections.
index c38b580661af81fd2ed7118486f48ff0936402b8..4b94b3ed73357db4659e2c3fde777e4e67b13e66 100644 (file)
@@ -58,7 +58,7 @@ ifname_client = hippo%d
 ifname_server = shippo%d
 max_clock_skew = 300
 
-ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip,%(ifname)s '%(rnets)s'
+ipif = userv root ipif %{local},%{peer},%{mtu},slip,%{ifname} '%{rnets}'
 
 mtu = 1500
 
@@ -694,11 +694,11 @@ impl InstanceConfig {
         .collect::<HashMap<String, String>>();
       let bad = parking_lot::Mutex::new(vec![]);
       *var = regex_replace_all!(
-        r#"%(?:%|\((\w+)\)s|.)"#,
+        r#"%(?:%|\((\w+)\)s|\{(\w+)\}|.)"#,
         &var,
-        |whole, k| (|| Ok::<_,String>({
+        |whole, k1, k2| (|| Ok::<_,String>({
           if whole == "%%" { "%" }
-          else if k != "" {
+          else if let Some(&k) = [k1,k2].iter().find(|&&s| s != "") {
             substs.get(k).ok_or_else(
               || format!("unknown key %({})s", k)
             )?