aboutsummaryrefslogtreecommitdiff
path: root/rex
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2019-11-29 14:20:05 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2019-11-29 14:58:25 +0200
commit59b8e53b47b7f64539ada837a5bfe660fe9f6eea (patch)
tree6374b63604b02262690e64a051d07c56723bbc61 /rex
parentb9c48f9a25f39057ec774cadcc89599e0359dc7e (diff)
downloadrex-59b8e53b47b7f64539ada837a5bfe660fe9f6eea.tar.gz
rex-59b8e53b47b7f64539ada837a5bfe660fe9f6eea.tar.bz2
New subcommands for rex group
rex group swap - swap two stack entries rex group drop - drop a stack entry The command rex group show takes new options: -a,-all, to show all stack entries, and -H,--hosts, to show hosts along with the host group name. The options are mutually exclusive.
Diffstat (limited to 'rex')
-rwxr-xr-xrex162
1 files changed, 127 insertions, 35 deletions
diff --git a/rex b/rex
index 06f48cd..fe90754 100755
--- a/rex
+++ b/rex
@@ -2736,7 +2736,7 @@ namespace eval ::config {
proc push {} {
global config
array set cv {}
- foreach key { option,hostgroup default,selected } {
+ foreach key { option,hostgroup default,selected default,predicate } {
if [info exists config($key)] {
set cv($key) $config($key)
}
@@ -3278,7 +3278,7 @@ proc savedefault {} {
proc rex_group_select {} {
global config
-
+
proc ::hostproc::prologue {} {
unset -nocomplain ::config(default,selected)
}
@@ -3297,25 +3297,26 @@ proc rex_group_select {} {
exit 1
}
unset -nocomplain config(option,hostgroup)
+ set config(default,predicate) [join $config(argv)]
::config::push
savedefault
}
-proc rex_group_drop {} {
+proc rex_group_pop {} {
global config
rex_parse_cmdline \
- -usage {rex group drop} \
- -docstring {Deselect the hostgroup}
+ -usage {rex group pop} \
+ -docstring {Pop current hostgroup off the stack}
+ unset -nocomplain config(default,selected)
+ unset -nocomplain config(default,predicate)
::config::pop
savedefault
}
proc rex_group_push {} {
- global argc
- global argv
global config
rex_parse_cmdline \
@@ -3327,49 +3328,137 @@ proc rex_group_push {} {
exit 1
}
- unset -nocomplain config(default,selected)
+ unset -nocomplain config(default,selected)
+ unset -nocomplain config(default,predicate)
option_set group [lindex $argv 0]
read_hostgroup [config_option hostgroup]
::config::push
-# ::config::export
-# hostlist_setup
savedefault
}
+proc rex_group_swap {} {
+ global argc
+ global config
+
+ rex_parse_cmdline \
+ -usage {rex group swap N} \
+ -docstring {Exchange top of group stack with its Nth entry}
+
+ if {$argc != 1} {
+ terror "bad arguments"
+ exit 1
+ }
+ set n [argcvshift]
+
+ if ![info exists config(default,hostgroup_stack)] {
+ terror "no group stack"
+ exit 2
+ }
+ if {$n <= 0 || $n > [expr [llength $config(default,hostgroup_stack)] - 1]} {
+ terror "bad frame index"
+ exit 2
+ }
+ set i [expr [llength $config(default,hostgroup_stack)] - $n - 1]
+ set t [lindex $config(default,hostgroup_stack) end]
+ lset config(default,hostgroup_stack) end \
+ [lindex $config(default,hostgroup_stack) $i]
+ lset config(default,hostgroup_stack) $i $t
+
+ savedefault
+}
+
+proc rex_group_drop {} {
+ global argc
+ global config
+
+ rex_parse_cmdline \
+ -usage {rex group drop N} \
+ -docstring {Remove Nth frame from the hostgroup stack}
+
+ set n [argcvshift]
+
+ if ![info exists config(default,hostgroup_stack)] {
+ terror "no group stack"
+ exit 2
+ }
+ if {$n < 0 || $n > [expr [llength $config(default,hostgroup_stack)] - 1]} {
+ terror "bad frame index"
+ exit 2
+ }
+
+ set i [expr [llength $config(default,hostgroup_stack)] - $n - 1]
+ set config(default,hostgroup_stack) \
+ [lreplace $config(default,hostgroup_stack) $i $i]
+
+ savedefault
+}
+
proc rex_group_show {} {
global argc
global argv
global config
- set hosts 0
-
+ set all false
+ set hosts false
+
rex_parse_cmdline \
-usage {rex group show [hosts]} \
- -docstring {Show selected hostgroup}
-
- if {$argc == 1} {
- if {[lindex $argv 0] == "hosts"} {
- set hosts 1
- } else {
- terror "unrecognized argument: [lindex $argv 0]"
- exit 2
+ -docstring {Show selected hostgroup} \
+ -group global {
+ all,a
+ {show all stack entries}
+ {uplevel 3 {set all true}}
+ hosts,H
+ {show hosts}
+ {uplevel 3 {set hosts true}}
}
- } elseif {$argc != 0} {
+
+ if {$argc != 0} {
terror "too many arguments"
exit 2
}
-
- if [info exists config(option,hostgroup)] {
- puts $config(option,hostgroup)
- } elseif [info exists config(default,selected)] {
- puts "selected hosts"
- } else {
+ if {$all && $hosts} {
+ terror "--all and --hosts cannot be used together"
exit 2
}
- if {$hosts && [info exists config(hosts)]} {
- foreach h $config(hosts) {
- puts $h
+
+ if {$all && [info exists config(default,hostgroup_stack)]} {
+ set n 0
+ foreach ent [lreverse $config(default,hostgroup_stack)] {
+ puts -nonewline [format "% 3d. " $n]
+ incr n
+
+ array unset cv
+ array set cv $ent
+ if [info exists cv(option,hostgroup)] {
+ puts $cv(option,hostgroup)
+ } elseif [info exists cv(default,selected)] {
+ if [info exists cv(default,predicate)] {
+ puts "selection: $cv(default,predicate)"
+ } else {
+ puts "selected hosts"
+ }
+ } else {
+ puts "MALFORMED ENTRY"
+ }
+ }
+ } else {
+ if [info exists config(option,hostgroup)] {
+ puts $config(option,hostgroup)
+ } elseif [info exists config(default,selected)] {
+ if [info exists config(default,predicate)] {
+ puts "selection: $config(default,predicate)"
+ } else {
+ puts "selected hosts"
+ }
+ } else {
+ exit 2
+ }
+ if {$hosts && [info exists config(hosts)]} {
+ foreach h $config(hosts) {
+ puts $h
+ }
}
}
}
@@ -3384,10 +3473,12 @@ proc rex_group {} {
-usage {rex group COMMAND [OPTIONS] [ARGS]} \
-docstring {Manipulate hostgroups} \
-footer {COMMANDs are:
+ drop remove given fram from stack
+ pop pop currently selected hostgroup off stack
+ push push new hostgroup
select select hosts matching predicate command
show show selected hostgroup (and hosts)
- push push new hostgroup
- pop pop currently selected hostgroup off stack
+ swap swap given frame and the top of stack
} \
-commit \
argc argv
@@ -3399,11 +3490,12 @@ proc rex_group {} {
set subcom [argcvshift]
switch -- $subcom {
- show rex_group_show
drop rex_group_drop
- pop rex_group_drop
- select rex_group_select
+ pop rex_group_pop
push rex_group_push
+ select rex_group_select
+ show rex_group_show
+ swap rex_group_swap
default {
terror "unknown subcommand $subcom; try 'rex group --usage' for details"

Return to:

Send suggestions and report system problems to the System administrator.