From f9b1ab9aaeacfcbf8d694cdaea6b3fd30df0fa2d Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sun, 14 Nov 2021 11:52:50 +0100 Subject: [PATCH] Add --prepend-on-unload on remove-path/module unuse Add the --prepend-on-unload option to the remove-path and module unuse sub-command to append specified paths when commands are evaluated in unload mode. If option is set prior path list specification, this path list which is unsets when modulefile loads is appended back when modulefile unloads. If a different path list is passed after option specification, this list is appended on unload mode instead of the list removed at load time. --prepend-on-unload option cannot be mixed with --index option. --- tcl/envmngt.tcl.in | 12 +++++++----- tcl/subcmd.tcl.in | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tcl/envmngt.tcl.in b/tcl/envmngt.tcl.in index 89e9f3c6..47dd962f 100644 --- a/tcl/envmngt.tcl.in +++ b/tcl/envmngt.tcl.in @@ -1250,7 +1250,7 @@ proc unload-path {cmd mode dflbhv args} { nop { return [list $bhv $var] } - append { + append - prepend { # set paths instead of removing them add-path unload-path load $bhv $cmd $separator $var {*}$path_list return [list $bhv $var] @@ -1436,7 +1436,7 @@ proc parsePathCommandArgs {cmd mode dflbhv args} { # everything passed after variable name is considered a value if {[info exists var]} { switch -- $arg { - --append-on-unload { + --append-on-unload - --prepend-on-unload { if {$cmd ne {remove-path}} { knerror "invalid option '$arg' for $cmd" } elseif {$mode ne {unload}} { @@ -1446,7 +1446,8 @@ proc parsePathCommandArgs {cmd mode dflbhv args} { set next_is_ignored 1 } } else { - set bhv append + set bhv [expr {$arg eq {--append-on-unload} ? {append} :\ + {prepend}}] # if another argument is set, current value list will be # withdrawn to start from new list set after this argument set next_is_reset 1 @@ -1505,11 +1506,12 @@ proc parsePathCommandArgs {cmd mode dflbhv args} { } set bhvopt $arg } - --append-on-unload { + --append-on-unload - --prepend-on-unload { if {$cmd ne {remove-path}} { knerror "invalid option '$arg' for $cmd" } elseif {$mode eq {unload}} { - set bhv append + set bhv [expr {$arg eq {--append-on-unload} ? {append} :\ + {prepend}}] } set bhvopt $arg } diff --git a/tcl/subcmd.tcl.in b/tcl/subcmd.tcl.in index 04c92879..3f51f3cc 100644 --- a/tcl/subcmd.tcl.in +++ b/tcl/subcmd.tcl.in @@ -1574,7 +1574,7 @@ proc runModuleUse {cmd mode pos args} { foreach path $args { switch -glob -- $path { - --remove-on-unload - --append-on-unload { + --remove-on-unload - --append-on-unload - --prepend-on-unload { if {$cmd ne {unuse}} { knerror "Invalid option '$path'" } else {