]> Cypherpunks repositories - dsc.git/commitdiff
DRY of boolean options
authorSergey Matveev <stargrave@stargrave.org>
Mon, 12 Jan 2026 11:11:40 +0000 (14:11 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 12 Jan 2026 11:11:40 +0000 (14:11 +0300)
jimlib/check-utils.tcl [new file with mode: 0644]
jimlib/net-utils.tcl
schema/srv/*/autostart/check
schema/ssh/enabled/check

diff --git a/jimlib/check-utils.tcl b/jimlib/check-utils.tcl
new file mode 100644 (file)
index 0000000..464b668
--- /dev/null
@@ -0,0 +1,13 @@
+proc parse-bool {v} {
+    if {$v == ""} {
+        return no
+    }
+    if {![string is boolean $v]} {
+        puts {is not boolean}
+        exit 1
+    }
+    if {$v} {
+        return yes
+    }
+    return no
+}
index a73310937cf78a3cb4b3d65295c5d71136314dfc70cd207b54e90f6b1696f702..5c24cda56c385789b75835ea969941f7c120462b66520d922fcad36e51ae73aa 100644 (file)
@@ -35,5 +35,3 @@ proc list-addrs {iface} {
     }
     return $addrs
 }
-
-package provide net-utils
index f4de234006119ec40950d370c808bb48a7ad0bd3c8532911ea5847c0e8d181a9..304cf9598b77c571faf007f2997d69833290158411cb93b9b42b3a6f627b3a9a 100755 (executable)
@@ -1,11 +1,5 @@
 #!/usr/bin/env jimsh
 
-set n [read -nonewline stdin]
-if {$n == ""} {
-    set n no
-}
-if {![string is boolean $n]} {
-    puts {is not boolean}
-    exit 1
-}
-puts $n
+package require check-utils
+set v [parse-bool [read -nonewline stdin]]
+puts $v
index f4de234006119ec40950d370c808bb48a7ad0bd3c8532911ea5847c0e8d181a9..304cf9598b77c571faf007f2997d69833290158411cb93b9b42b3a6f627b3a9a 100755 (executable)
@@ -1,11 +1,5 @@
 #!/usr/bin/env jimsh
 
-set n [read -nonewline stdin]
-if {$n == ""} {
-    set n no
-}
-if {![string is boolean $n]} {
-    puts {is not boolean}
-    exit 1
-}
-puts $n
+package require check-utils
+set v [parse-bool [read -nonewline stdin]]
+puts $v