@@ -1679,10 +1679,64 @@ proc sh-to-mod {args} {
16791679 return $modcontent
16801680}
16811681
1682- proc source-sh {shell script args} {
1682+ proc parseSourceShArgs {args} {
1683+ set elt_ignored_list {}
1684+
1685+ set i 0
1686+ foreach arg $args {
1687+ incr i
1688+ if {[info exists nextargisval]} {
1689+ # #nagelfar vartype nextargisval varName
1690+ set $nextargisval $arg
1691+ unset nextargisval
1692+ } else {
1693+ switch -glob -- $arg {
1694+ --ignore {
1695+ set nextargisval ignore_opt_raw
1696+ }
1697+ -* {
1698+ knerror " Invalid option '$arg '"
1699+ }
1700+ default {
1701+ set shell $arg
1702+ # end option parsing: remaining elts are allowed values
1703+ break
1704+ }
1705+ }
1706+ set prevarg $arg
1707+ }
1708+ }
1709+
1710+ if {[info exists nextargisval]} {
1711+ knerror " Missing value for '$prevarg ' option"
1712+ }
1713+
1714+ if {![info exists shell] || $i == [llength $args ]} {
1715+ knerror " wrong # args: should be \" source-sh ?--ignore? ?eltlist? shell\
1716+ script ?arg ...?\" "
1717+ }
1718+
1719+ set script_args [lassign [lrange $args $i end] script]
1720+
1721+ if {[info exists ignore_opt_raw]} {
1722+ set elt_ignored_list [split $ignore_opt_raw :]
1723+ set allowed_elt_ignored_list {envvar function alias chdir complete}
1724+ foreach elt_ignored $elt_ignored_list {
1725+ if {$elt_ignored ni $allowed_elt_ignored_list } {
1726+ knerror " Invalid ignored element '$elt_ignored '"
1727+ }
1728+ }
1729+ }
1730+
1731+ return [list $elt_ignored_list $shell $script $script_args ]
1732+ }
1733+
1734+ proc source-sh {args} {
1735+ lassign [parseSourceShArgs {*}$args ] elt_ignored_list shell script\
1736+ script_args
16831737 # evaluate script and get the environment changes it performs translated
16841738 # into modulefile commands
1685- set shtomodargs [list $shell $script {*}$args ]
1739+ set shtomodargs [list $shell $script {*}$script_args ]
16861740 set modcontent [sh-to-mod {*}$shtomodargs ]
16871741
16881742 # register resulting modulefile commands
@@ -1699,8 +1753,10 @@ proc source-sh {shell script args} {
16991753}
17001754
17011755# undo source-sh in unload mode
1702- proc source-sh-un {shell script args} {
1703- set shtomodargs [list $shell $script {*}$args ]
1756+ proc source-sh-un {args} {
1757+ lassign [parseSourceShArgs {*}$args ] elt_ignored_list shell script\
1758+ script_args
1759+ set shtomodargs [list $shell $script {*}$script_args ]
17041760 # find commands resulting from source-sh evaluation recorded in env
17051761 set modcontent [getLoadedSourceShScriptContent [currentState modulename]\
17061762 $shtomodargs ]
@@ -1715,8 +1771,10 @@ proc source-sh-un {shell script args} {
17151771}
17161772
17171773# report underlying modulefile cmds in display mode
1718- proc source-sh-di {shell script args} {
1719- set shtomodargs [list $shell $script {*}$args ]
1774+ proc source-sh-di {args} {
1775+ lassign [parseSourceShArgs {*}$args ] elt_ignored_list shell script\
1776+ script_args
1777+ set shtomodargs [list $shell $script {*}$script_args ]
17201778
17211779 # if module loaded, get as much content from environment as possible
17221780 if {[is-loaded [currentState modulename]]} {
0 commit comments