Add support for --delim=C arg syntax on *-path cmds

Closes #140
This commit is contained in:
Xavier Delaruelle
2017-12-15 07:24:39 +01:00
parent 09841ad704
commit fe1f465383
10 changed files with 173 additions and 71 deletions

View File

@@ -2018,6 +2018,9 @@ proc parsePathCommandArgs {cmd args} {
{-d} - {-delim} - {--delim} {
set next_is_delim 1
}
{--delim=*} {
set delim [string range $arg 8 end]
}
default {
if {$next_is_delim} {
set delim $arg
@@ -2034,6 +2037,8 @@ proc parsePathCommandArgs {cmd args} {
# adapt with default value or raise error if some arguments are missing
if {![info exists delim]} {
set delim $g_def_separator
} elseif {$delim eq ""} {
error "$cmd should get a non-empty path delimiter"
}
if {![info exists var]} {
error "$cmd should get an environment variable name"
@@ -2044,6 +2049,8 @@ proc parsePathCommandArgs {cmd args} {
error "$cmd should get a value for environment variable $var"
}
reportDebug "parsePathCommandArgs: (delim=$delim, var=$var, val=$val)"
return [list $delim $var $val]
}

View File

@@ -13,7 +13,7 @@
#
# Description: Testuite modulefile
# Command:
# Sub-Command: prepend-path --delim { }
# Sub-Command: prepend-path --delim={ }
#
# Invocation: load @M@/@V@
# Comment: %C{

View File

@@ -0,0 +1,24 @@
#%Module1.0
##############################################################################
# Modules Revision 3.0
# Providing a flexible user environment
#
# File: prepend/%M%
# Revision: %I%
# First Edition: 2017/12/15
# Last Mod.: %U%, %G%
#
# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr
#
# Description: Test bad argument list
# Command:
# Sub-Command: prepend-path
#
# Invocation: load @M@/@V@
# Comment: %C{
# }C%
#
##############################################################################
prepend-path --delim= PATH /path/to

View File

@@ -0,0 +1,26 @@
#%Module1.0
##############################################################################
# Modules Revision 3.0
# Providing a flexible user environment
#
# File: prepend/%M%
# Revision: %I%
# First Edition: 2017/12/15
# Last Mod.: %U%, %G%
#
# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr
#
# Description: Testuite modulefile
# Command:
# Sub-Command: prepend-path --delim=,
#
# Invocation: load @M@/@V@
# Comment: %C{
# Check prepending using a different delimiter with
# --delim=C argument form
# }C%
#
##############################################################################
prepend-path --delim=, testsuite {http://foobar.com}

View File

@@ -53,6 +53,23 @@ lappend ans [list setpath _LMFILES_ $modulefile]
test_cmd_re "ALL" "load $module" $ans
#
# Test the --delim=C argument form
#
set ts_new "$ts_3,$ts_1,$ts_2"
set env(testsuite) "$ts_1,$ts_2"
set module "prepend/1.7"
set modulefile "$modpath/$module"
set ans [list]
lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
test_cmd_re "sh" "load $module" $ans
#
# Try bad argument list: missing variable name
#
@@ -80,6 +97,15 @@ set modulefile "$modpath/$module"
set ts_err "$moderr_msgs: prepend-path should get a valid environment variable name\n In '$modulefile'\n$err_contact"
testouterr_cmd "sh" "load $module" "ERR" $ts_err
#
# Try bad argument list: empty delimiter value
#
set module "prepend/1.6"
set modulefile "$modpath/$module"
set ts_err "$moderr_msgs: prepend-path should get a non-empty path delimiter\n In '$modulefile'\n$err_contact"
testouterr_cmd "sh" "load $module" "ERR" $ts_err
#
# Cleanup
#

View File

@@ -93,6 +93,17 @@ set env(LOADEDMODULES) $module
set ts_err "$moderr_msgs: prepend-path should get a valid environment variable name\n In '$modulefile'\n$err_contact"
testouterr_cmd "sh" "unload $module" "ERR" $ts_err
#
# Try bad argument list: empty delimiter value
#
set module "prepend/1.6"
set modulefile "$modpath/$module"
set env(_LMFILES_) $modulefile
set env(LOADEDMODULES) $module
set ts_err "$moderr_msgs: prepend-path should get a non-empty path delimiter\n In '$modulefile'\n$err_contact"
testouterr_cmd "sh" "unload $module" "ERR" $ts_err
#
# Cleanup
#

View File

@@ -52,11 +52,13 @@ lappend ans [list setpath FOO "$path1:$path2"]
testouterr_cmd_re "ALL" "append-path FOO $path2" $ans ""
testouterr_cmd_re "sh" "append-path -d : FOO $path2" $ans ""
testouterr_cmd_re "sh" "append-path --delim : FOO $path2" $ans ""
testouterr_cmd_re "sh" "append-path --delim=: FOO $path2" $ans ""
set ans [list]
lappend ans [list setpath FOO "$path1,$path2"]
testouterr_cmd_re "sh" "append-path -d , FOO $path2" $ans ""
testouterr_cmd_re "sh" "append-path --delim , FOO $path2" $ans ""
testouterr_cmd_re "sh" "append-path --delim=, FOO $path2" $ans ""
if { $verbose > 0 } {
@@ -77,6 +79,7 @@ testouterr_cmd_re "sh" "append-path FOO" "ERR" "$error_msgs: Unexpected number o
testouterr_cmd_re "sh" "append-path -d : FOO" "ERR" "$error_msgs: append-path should get a value for environment variable FOO"
testouterr_cmd_re "sh" "append-path -d :" "ERR" "$error_msgs: append-path should get an environment variable name"
testouterr_cmd_re "sh" "append-path -d : " "ERR" "$error_msgs: append-path should get a valid environment variable name"
testouterr_cmd_re "sh" "append-path --delim= FOO /path/to" "ERR" "$error_msgs: append-path should get a non-empty path delimiter"
#

View File

@@ -52,11 +52,13 @@ lappend ans [list setpath FOO "$path2:$path1"]
testouterr_cmd_re "ALL" "prepend-path FOO $path2" $ans ""
testouterr_cmd_re "sh" "prepend-path -d : FOO $path2" $ans ""
testouterr_cmd_re "sh" "prepend-path --delim : FOO $path2" $ans ""
testouterr_cmd_re "sh" "prepend-path --delim=: FOO $path2" $ans ""
set ans [list]
lappend ans [list setpath FOO "$path2,$path1"]
testouterr_cmd_re "sh" "prepend-path -d , FOO $path2" $ans ""
testouterr_cmd_re "sh" "prepend-path --delim , FOO $path2" $ans ""
testouterr_cmd_re "sh" "prepend-path --delim=, FOO $path2" $ans ""
if { $verbose > 0 } {

View File

@@ -57,6 +57,7 @@ lappend ans [list setpath FOO "$path1"]
testouterr_cmd_re "ALL" "remove-path FOO $path2" $ans ""
testouterr_cmd_re "sh" "remove-path -d : FOO $path2" $ans ""
testouterr_cmd_re "sh" "remove-path --delim : FOO $path2" $ans ""
testouterr_cmd_re "sh" "remove-path --delim=: FOO $path2" $ans ""
set ans [list]
lappend ans [list setpath FOO "$path1:$path2"]
@@ -72,6 +73,7 @@ set ans [list]
lappend ans [list setpath FOO "$path1"]
testouterr_cmd_re "sh" "remove-path -d , FOO $path2" $ans ""
testouterr_cmd_re "sh" "remove-path --delim , FOO $path2" $ans ""
testouterr_cmd_re "sh" "remove-path --delim=, FOO $path2" $ans ""
if { $verbose > 0 } {
@@ -89,6 +91,7 @@ testouterr_cmd_re "sh" "remove-path FOO" "ERR" "$error_msgs: Unexpected number o
testouterr_cmd_re "sh" "remove-path -d : FOO" "ERR" "$error_msgs: remove-path should get a value for environment variable FOO"
testouterr_cmd_re "sh" "remove-path -d :" "ERR" "$error_msgs: remove-path should get an environment variable name"
testouterr_cmd_re "sh" "remove-path -d : " "ERR" "$error_msgs: remove-path should get a valid environment variable name"
testouterr_cmd_re "sh" "remove-path --delim= FOO /path/to" "ERR" "$error_msgs: remove-path should get a non-empty path delimiter"
#

View File

@@ -37,76 +37,76 @@ set len [string length $modpath]
set lrep [expr {($test_cols - $len - 2)/2}]
set rrep [expr {$test_cols - $len - 2 - $lrep}]
set ts_sh "[string repeat {-} $lrep] $modpath [string repeat {-} $rrep]
alias/1.0 info/shells loc_rc7/1.2 modbad/is-avail symlink/0.9
alias/2.0 info/shellsexp loc_rc7/bar(@) modbad/is-loaded symlink/1(@)
append/0.1 info/specified(foo) loc_rc8/0.9(@) modbad/is-saved symlink/1.2(default:new)
append/0.2 info/type loc_rc8/1.0 modbad/is-used symlink/bar(@)
append/0.3 info/user loc_sym/1.0 modbad/path symlink2/1.0
append/0.4 info/userexp loc_sym/alias1 modbad/paths symlink2/2.0
append/0.5 inforc/1.0 loc_sym/alias2 modbad/prepend-path system/2.0
append/1.0 inforc/2.0(avail:bar:default) loc_sym/alias3 modbad/remove-path test/1.0
append/1.1 inforc/foo(@) loc_sym/alias4 module/2.0 test/1.2
append/1.3 load/00 loc_sym/alias5 module/bad test/2.0
append/1.4 load/10 loc_sym/alias6 module/err tr2_loc(trreg)
append/1.5 load/11 loc_sym/alias7 module/lbad tr2_loc/al1(tr2unstable:@)
append/2.0 load/12 loc_sym/exec1 module/lerr tr2_loc/al2(tr2bar:@)
append/2.1 load/13 loc_sym/exec2 module/lunk tr2_loc/al3(default:tr2exp:trreg:@)
append/2.2 load/14 loc_sym/getvers1 module/meta tr2_loc/al4(@)
averssort/1(@) load/15 loc_sym/getvers2 module/unk tr2_loc/al5(default:trreg:@)
averssort/1.2.4(@) load/16 loc_sym/getvers3 prepend/0.1 tr_loc/al1(tr2unstable:trunstable:@)
averssort/1.10(@) load/17 loc_sym/getvers4 prepend/0.2 tr_loc/al2(default:tr2bar:tr2exp:trbar:trreg:@)
bad/after(good) load/18 loc_sym/getvers5 prepend/0.3 tr_loc/al3(trexp:@)
bad/before load/19 loc_sym/getvers6 prepend/0.4 tr_loc/al4(@)
bad2/body load/20 loc_sym/getvers7 prepend/0.5 tr_loc/al5(@)
bad2/proc load/21 loc_sym/getvers8 prepend/1.0 trace/all_off
break/1.0 load/22 loc_sym/versinf1 prepend/1.1 trace/all_on
break/2.0 load/23 loc_sym/versinf2 prepend/1.3 uname/domain
break/3.0 load/24 loc_sym/versinf3 prepend/1.4 uname/machine
break/4.0 load/25 loc_sym/versinf4 prepend/1.5 uname/nodename
break/5.0 load/26 loc_sym/versinf5 prepend/2.0 uname/release
break/6.0 load/27 loc_sym/versinf6 prepend/2.1 uname/sysname
chdir/1.0 load/28 loc_sym/versinf7 prepend/2.2 uname/version
chdir/2.0 load/29 loc_sym/version1 prereq/full unsetenv/0.8
chdir/3.0 load/30 loc_sym/version2 prereq/fullpath unsetenv/0.9
chdir/4.0 load/all(default) loc_sym/version3 prereq/module unsetenv/1.0
coll/a loc_def/default loc_sym/version4 prereq/orlist use/1.0(default)
coll/b loc_def/truedef loc_sym/version5 puts/1 use/2.0
coll/c loc_dv1/1.0 loc_sym/version6 puts/2 use/2.1
coll/d loc_dv1/2.0 loc_sym/version7 puts/3 use/2.2
conflict/full loc_dv2/1.0(default) loc_sym/version8 puts/4 use/3.0
conflict/fullpath loc_dv2/2.0 loc_sym/version9 puts/5 use/3.1
conflict/module loc_dv3/1.0 loc_sym/version10 puts/6 use/3.2
continue/1.0 loc_dv3/2.0 loc_sym/version11 puts/7 use/4.0
continue/2.0 loc_dv4/1.0 loc_sym/version12 recurs/modA user/adv
continue/3.0 loc_dv6/1.0 loc_sym/version13 recurs/modB user/advanced
continue/4.0 loc_dv6/2.0/1.0 loc_sym/version14 remove/0.3 user/exp
continue/5.0 loc_dv7/1.0 loc_sym/version15 remove/0.4 user/expert
continue/6.0 loc_dv7/2.0(default) loc_sym/version16 remove/0.5 user/nov
dirmodalias(@) loc_dv7/2.0/1.0 loc_sym/version17 remove/1.0 user/novice
dirmodalias/1.0 loc_dv7/3.0 loc_sym/version18 remove/1.3 user/undef
empty/1.0 loc_dv8/1.0 loc_sym/version19 remove/1.4 verbose/msg
eschars/1.0 loc_dv8/2.0 loc_sym/version20 remove/1.5 verbose/off
exit/1.0 loc_dv9/1.0(default) loc_sym/version21 remove/2.0 verbose/on
exit/2.0 loc_dv9/2.0 loc_sym/version22 setenv/0.8 verbose/undef
exit/3.0 loc_fq/1.0 loc_sym/version23 setenv/1.0 versions/1.1
exit/4.0 loc_rc1/1.0(foo) loc_tr(reg) source/0.9 versions/1.2
getenv/1.0 loc_rc1/2.0 loc_tr/1.0(cur:stable) source/1.0 versions/1.3
help/2.0 loc_rc2/1.0(bar:blah:foo) loc_tr/2.0(next:tr2unstable:trunstable:unstable) spread/1.0 verssort/1
info/command loc_rc2/2.0 loc_tr/3.0(bar:default:exp:foo:reg:tr2bar:tr2exp:trbar:trexp:trreg) spread/2.0 verssort/1.2.1
info/commandexp loc_rc3/1.0(default) loc_tr/al1(unstable:@) spread/3.0 verssort/1.2.4
info/isavail loc_rc3/2.0(cur:stable) loc_tr/al2(bar:default:exp:reg:trexp:@) spread/4.0 verssort/1.8-2015-12-01
info/isloaded loc_rc3/3.0(chk:exp:new:test) loc_tr/al3(default:exp:reg:@) spread/5.0 verssort/1.8-2016-02-01
info/issaved loc_rc4/1.0 loc_tr/al4(default:reg:@) spread/6.0 verssort/1.10
info/isused loc_rc4/2.0(default) log/badfac spread/7.0 whatis/lines
info/loaded loc_rc4/3.0 log/err_both_1 spread/8.0 whatis/multiple
info/mode1 loc_rc5/1.0 log/err_both_2 spreadrc/dir1/1.0 whatis/none
info/mode2 loc_rc5/2.0 log/err_file spreadrc/dir2/1.0 whatis/single
info/mode3 loc_rc6/0.9 log/err_syslog spreadrc/dir3/1.0 whatis/string
info/mode4 loc_rc6/1(@) modbad/append-path spreadrc/dir4/1.0 x-resource/1
info/mode5 loc_rc6/1.2(default:new) modbad/autoinit spreadrc/dir5/1.0
info/mode6 loc_rc6/bar(@) modbad/foo spreadrc/dir6/1.0
info/name loc_rc7/0.9 modbad/help spreadrc/dir7/1.0
info/others loc_rc7/1(@) modbad/info-loaded spreadrc/dir8/1.0 "
alias/1.0 info/shells loc_rc7/1.2 modbad/is-avail spreadrc/dir7/1.0
alias/2.0 info/shellsexp loc_rc7/bar(@) modbad/is-loaded spreadrc/dir8/1.0
append/0.1 info/specified(foo) loc_rc8/0.9(@) modbad/is-saved symlink/0.9
append/0.2 info/type loc_rc8/1.0 modbad/is-used symlink/1(@)
append/0.3 info/user loc_sym/1.0 modbad/path symlink/1.2(default:new)
append/0.4 info/userexp loc_sym/alias1 modbad/paths symlink/bar(@)
append/0.5 inforc/1.0 loc_sym/alias2 modbad/prepend-path symlink2/1.0
append/1.0 inforc/2.0(avail:bar:default) loc_sym/alias3 modbad/remove-path symlink2/2.0
append/1.1 inforc/foo(@) loc_sym/alias4 module/2.0 system/2.0
append/1.3 load/00 loc_sym/alias5 module/bad test/1.0
append/1.4 load/10 loc_sym/alias6 module/err test/1.2
append/1.5 load/11 loc_sym/alias7 module/lbad test/2.0
append/2.0 load/12 loc_sym/exec1 module/lerr tr2_loc(trreg)
append/2.1 load/13 loc_sym/exec2 module/lunk tr2_loc/al1(tr2unstable:@)
append/2.2 load/14 loc_sym/getvers1 module/meta tr2_loc/al2(tr2bar:@)
averssort/1(@) load/15 loc_sym/getvers2 module/unk tr2_loc/al3(default:tr2exp:trreg:@)
averssort/1.2.4(@) load/16 loc_sym/getvers3 prepend/0.1 tr2_loc/al4(@)
averssort/1.10(@) load/17 loc_sym/getvers4 prepend/0.2 tr2_loc/al5(default:trreg:@)
bad/after(good) load/18 loc_sym/getvers5 prepend/0.3 tr_loc/al1(tr2unstable:trunstable:@)
bad/before load/19 loc_sym/getvers6 prepend/0.4 tr_loc/al2(default:tr2bar:tr2exp:trbar:trreg:@)
bad2/body load/20 loc_sym/getvers7 prepend/0.5 tr_loc/al3(trexp:@)
bad2/proc load/21 loc_sym/getvers8 prepend/1.0 tr_loc/al4(@)
break/1.0 load/22 loc_sym/versinf1 prepend/1.1 tr_loc/al5(@)
break/2.0 load/23 loc_sym/versinf2 prepend/1.3 trace/all_off
break/3.0 load/24 loc_sym/versinf3 prepend/1.4 trace/all_on
break/4.0 load/25 loc_sym/versinf4 prepend/1.5 uname/domain
break/5.0 load/26 loc_sym/versinf5 prepend/1.6 uname/machine
break/6.0 load/27 loc_sym/versinf6 prepend/1.7 uname/nodename
chdir/1.0 load/28 loc_sym/versinf7 prepend/2.0 uname/release
chdir/2.0 load/29 loc_sym/version1 prepend/2.1 uname/sysname
chdir/3.0 load/30 loc_sym/version2 prepend/2.2 uname/version
chdir/4.0 load/all(default) loc_sym/version3 prereq/full unsetenv/0.8
coll/a loc_def/default loc_sym/version4 prereq/fullpath unsetenv/0.9
coll/b loc_def/truedef loc_sym/version5 prereq/module unsetenv/1.0
coll/c loc_dv1/1.0 loc_sym/version6 prereq/orlist use/1.0(default)
coll/d loc_dv1/2.0 loc_sym/version7 puts/1 use/2.0
conflict/full loc_dv2/1.0(default) loc_sym/version8 puts/2 use/2.1
conflict/fullpath loc_dv2/2.0 loc_sym/version9 puts/3 use/2.2
conflict/module loc_dv3/1.0 loc_sym/version10 puts/4 use/3.0
continue/1.0 loc_dv3/2.0 loc_sym/version11 puts/5 use/3.1
continue/2.0 loc_dv4/1.0 loc_sym/version12 puts/6 use/3.2
continue/3.0 loc_dv6/1.0 loc_sym/version13 puts/7 use/4.0
continue/4.0 loc_dv6/2.0/1.0 loc_sym/version14 recurs/modA user/adv
continue/5.0 loc_dv7/1.0 loc_sym/version15 recurs/modB user/advanced
continue/6.0 loc_dv7/2.0(default) loc_sym/version16 remove/0.3 user/exp
dirmodalias(@) loc_dv7/2.0/1.0 loc_sym/version17 remove/0.4 user/expert
dirmodalias/1.0 loc_dv7/3.0 loc_sym/version18 remove/0.5 user/nov
empty/1.0 loc_dv8/1.0 loc_sym/version19 remove/1.0 user/novice
eschars/1.0 loc_dv8/2.0 loc_sym/version20 remove/1.3 user/undef
exit/1.0 loc_dv9/1.0(default) loc_sym/version21 remove/1.4 verbose/msg
exit/2.0 loc_dv9/2.0 loc_sym/version22 remove/1.5 verbose/off
exit/3.0 loc_fq/1.0 loc_sym/version23 remove/2.0 verbose/on
exit/4.0 loc_rc1/1.0(foo) loc_tr(reg) setenv/0.8 verbose/undef
getenv/1.0 loc_rc1/2.0 loc_tr/1.0(cur:stable) setenv/1.0 versions/1.1
help/2.0 loc_rc2/1.0(bar:blah:foo) loc_tr/2.0(next:tr2unstable:trunstable:unstable) source/0.9 versions/1.2
info/command loc_rc2/2.0 loc_tr/3.0(bar:default:exp:foo:reg:tr2bar:tr2exp:trbar:trexp:trreg) source/1.0 versions/1.3
info/commandexp loc_rc3/1.0(default) loc_tr/al1(unstable:@) spread/1.0 verssort/1
info/isavail loc_rc3/2.0(cur:stable) loc_tr/al2(bar:default:exp:reg:trexp:@) spread/2.0 verssort/1.2.1
info/isloaded loc_rc3/3.0(chk:exp:new:test) loc_tr/al3(default:exp:reg:@) spread/3.0 verssort/1.2.4
info/issaved loc_rc4/1.0 loc_tr/al4(default:reg:@) spread/4.0 verssort/1.8-2015-12-01
info/isused loc_rc4/2.0(default) log/badfac spread/5.0 verssort/1.8-2016-02-01
info/loaded loc_rc4/3.0 log/err_both_1 spread/6.0 verssort/1.10
info/mode1 loc_rc5/1.0 log/err_both_2 spread/7.0 whatis/lines
info/mode2 loc_rc5/2.0 log/err_file spread/8.0 whatis/multiple
info/mode3 loc_rc6/0.9 log/err_syslog spreadrc/dir1/1.0 whatis/none
info/mode4 loc_rc6/1(@) modbad/append-path spreadrc/dir2/1.0 whatis/single
info/mode5 loc_rc6/1.2(default:new) modbad/autoinit spreadrc/dir3/1.0 whatis/string
info/mode6 loc_rc6/bar(@) modbad/foo spreadrc/dir4/1.0 x-resource/1
info/name loc_rc7/0.9 modbad/help spreadrc/dir5/1.0
info/others loc_rc7/1(@) modbad/info-loaded spreadrc/dir6/1.0 "
#
# test