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.
This commit is contained in:
Xavier Delaruelle
2021-11-14 11:52:50 +01:00
parent f4d3a1bbab
commit f9b1ab9aae
2 changed files with 8 additions and 6 deletions

View File

@@ -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
}

View File

@@ -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 {