From 098ba1aa8208118e99b2f20afd58c8c59fbdc6d45bd9812e23c493f40302bc9b Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 12 Jan 2026 14:11:40 +0300 Subject: [PATCH] DRY of boolean options --- jimlib/check-utils.tcl | 13 +++++++++++++ jimlib/net-utils.tcl | 2 -- schema/srv/*/autostart/check | 12 +++--------- schema/ssh/enabled/check | 12 +++--------- 4 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 jimlib/check-utils.tcl diff --git a/jimlib/check-utils.tcl b/jimlib/check-utils.tcl new file mode 100644 index 0000000..464b668 --- /dev/null +++ b/jimlib/check-utils.tcl @@ -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 +} diff --git a/jimlib/net-utils.tcl b/jimlib/net-utils.tcl index a733109..5c24cda 100644 --- a/jimlib/net-utils.tcl +++ b/jimlib/net-utils.tcl @@ -35,5 +35,3 @@ proc list-addrs {iface} { } return $addrs } - -package provide net-utils diff --git a/schema/srv/*/autostart/check b/schema/srv/*/autostart/check index f4de234..304cf95 100755 --- a/schema/srv/*/autostart/check +++ b/schema/srv/*/autostart/check @@ -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 diff --git a/schema/ssh/enabled/check b/schema/ssh/enabled/check index f4de234..304cf95 100755 --- a/schema/ssh/enabled/check +++ b/schema/ssh/enabled/check @@ -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 -- 2.52.0