-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodulecmd.tcl
executable file
·4673 lines (4129 loc) · 142 KB
/
modulecmd.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# \
tclshbin=$(type -p tclsh) && exec $tclshbin "$0" "$@"
# \
[ -x /usr/local/bin/tclsh ] && exec /usr/local/bin/tclsh "$0" "$@"
# \
[ -x /usr/bin/tclsh ] && exec /usr/bin/tclsh "$0" "$@"
# \
[ -x /bin/tclsh ] && exec /bin/tclsh "$0" "$@"
# \
echo "FATAL: module: Could not find tclsh in \$PATH or in standard directories" >&2; exit 1
# MODULECMD.TCL, a pure TCL implementation of the module command
# Copyright (C) 2002-2004 Mark Lakata
# Copyright (C) 2004-2017 Kent Mein
# Copyright (C) 2016-2017 Xavier Delaruelle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
#
# Some Global Variables.....
#
set MODULES_CURRENT_VERSION 1.782
set MODULES_CURRENT_RELEASE_DATE "2017-03-14"
set g_debug 0 ;# Set to 1 to enable debugging
set error_count 0 ;# Start with 0 errors
set g_autoInit 0
set g_inhibit_interp 0 ;# Modulefile interpretation disabled if == 1
set g_inhibit_errreport 0 ;# Non-critical error reporting disabled if == 1
set g_force 0 ;# Path element reference counting if == 0
set CSH_LIMIT 4000 ;# Workaround for commandline limits in csh
set flag_default_dir 1 ;# Report default directories
set flag_default_mf 1 ;# Report default modulefiles and version alias
# Used to tell if a machine is running Windows or not
proc isWin {} {
global tcl_platform
if { $tcl_platform(platform) eq "windows" } {
return 1
} else {
return 0
}
}
#
# Set Default Path separator
#
if { [isWin] } {
set g_def_separator "\;"
} else {
set g_def_separator ":"
}
# Dynamic columns
set DEF_COLUMNS 80 ;# Default size of columns for formatting
if {[catch {exec stty size} stty_size] == 0 && $stty_size ne ""} {
set DEF_COLUMNS [lindex $stty_size 1]
}
# Use MODULECONTACT variable to set your support email address
if {[info exists env(MODULECONTACT)]} {
set contact $env(MODULECONTACT)
} else {
# Or change this to your support email address...
set contact "root@localhost"
}
# Set some directories to ignore when looking for modules.
set ignoreDir(CVS) 1
set ignoreDir(RCS) 1
set ignoreDir(SCCS) 1
set ignoreDir(.svn) 1
set ignoreDir(.git) 1
global g_shellType
global g_shell
set show_oneperline 0 ;# Gets set if you do module list/avail -t
set show_modtimes 0 ;# Gets set if you do module list/avail -l
set show_filter "" ;# Gets set if you do module avail -d or -L
proc raiseErrorCount {} {
global error_count
incr error_count
}
proc renderError {} {
global g_shellType error_count g_debug
if {$g_debug} {
report "Error: $error_count error(s) detected."
}
if {[info exists g_shellType]} {
switch -- $g_shellType {
csh {
puts stdout "/bin/false;"
}
sh {
puts stdout "/bin/false;"
}
fish {
puts stdout "/bin/false;"
}
tcl {
puts stdout "exec /bin/false;"
}
cmd {
# nothing needed, reserved for future cygwin, MKS, etc
}
perl {
puts stdout "die \"modulefile.tcl: $error_count error(s)\
detected!\\n\""
}
python {
puts stdout "raise RuntimeError(\
'modulefile.tcl: $error_count error(s) detected!')"
}
lisp {
puts stdout "(error \"modulefile.tcl:\
$error_count error(s) detected!\")"
}
}
}
}
#
# Debug, Info, Warnings and Error message handling.
#
proc reportDebug {message {nonewline ""}} {
global g_debug
if {$g_debug} {
report "DEBUG $message" "$nonewline"
}
}
proc reportWarning {message {nonewline ""}} {
global g_inhibit_errreport
if {!$g_inhibit_errreport} {
report "WARNING: $message" "$nonewline"
}
}
proc reportError {message {nonewline ""}} {
global g_inhibit_errreport
# if report disabled, also disable error raise to get a coherent
# behavior (if no message printed, no error code change)
if {!$g_inhibit_errreport} {
raiseErrorCount
report "ERROR: $message" "$nonewline"
}
}
proc reportErrorAndExit {message} {
raiseErrorCount
renderError
error "$message"
}
proc reportInternalBug {message} {
global contact g_inhibit_errreport
# if report disabled, also disable error raise to get a coherent
# behavior (if no message printed, no error code change)
if {!$g_inhibit_errreport} {
raiseErrorCount
report "Module ERROR: $message\nPlease contact: $contact"
}
}
proc report {message {nonewline ""}} {
if {$nonewline ne ""} {
puts -nonewline stderr "$message"
} else {
puts stderr "$message"
}
}
# raise error to top level, but no message as information have already
# been printed by a previous report* call
proc exitOnError {} {
renderError
error ""
}
# disable error reporting (non-critical report only) unless debug enabled
proc inhibitErrorReport {} {
global g_inhibit_errreport g_debug
if {!$g_debug} {
set g_inhibit_errreport 1
}
}
proc reenableErrorReport {} {
global g_inhibit_errreport
set g_inhibit_errreport 0
}
########################################################################
# Use a slave TCL interpreter to execute modulefiles
#
proc unset-env {var} {
global env
if {[info exists env($var)]} {
reportDebug "unset-env: $var"
unset env($var)
}
}
proc execute-modulefile {modfile {exit_on_error 1}} {
global g_debug g_inhibit_interp g_inhibit_errreport
global ModulesCurrentModulefile
global g_moduleProcs g_moduleVars
set ModulesCurrentModulefile $modfile
# skip modulefile if interpretation has been inhibited
if {$g_inhibit_interp} {
reportDebug "execute-modulefile: Skipping $modfile"
return 1
}
reportDebug "execute-modulefile: Starting $modfile"
set slave __[currentModuleName]
if {![interp exists $slave]} {
interp create $slave
interp alias $slave setenv {} setenv
interp alias $slave unsetenv {} unsetenv
interp alias $slave getenv {} getenv
interp alias $slave system {} system
interp alias $slave chdir {} chdir
interp alias $slave append-path {} append-path
interp alias $slave prepend-path {} prepend-path
interp alias $slave remove-path {} remove-path
interp alias $slave prereq {} prereq
interp alias $slave conflict {} conflict
interp alias $slave is-loaded {} is-loaded
interp alias $slave module {} module
interp alias $slave module-info {} module-info
interp alias $slave module-whatis {} module-whatis
interp alias $slave set-alias {} set-alias
interp alias $slave unset-alias {} unset-alias
interp alias $slave uname {} uname
interp alias $slave x-resource {} x-resource
interp alias $slave exit {} exitModfileCmd
interp alias $slave module-version {} module-version
interp alias $slave module-alias {} module-alias
interp alias $slave module-trace {} module-trace
interp alias $slave module-verbosity {} module-verbosity
interp alias $slave module-user {} module-user
interp alias $slave module-log {} module-log
interp alias $slave reportInternalBug {} reportInternalBug
interp alias $slave reportWarning {} reportWarning
interp alias $slave reportError {} reportError
interp alias $slave raiseErrorCount {} raiseErrorCount
interp alias $slave report {} report
interp alias $slave isWin {} isWin
interp eval $slave {global ModulesCurrentModulefile g_debug\
g_inhibit_interp g_inhibit_errreport}
interp eval $slave [list "set" "ModulesCurrentModulefile" $modfile]
interp eval $slave [list "set" "g_debug" $g_debug]
interp eval $slave [list "set" "g_inhibit_interp" $g_inhibit_interp]
interp eval $slave [list "set" "g_inhibit_errreport"\
$g_inhibit_errreport]
foreach name [array names g_moduleProcs] {
foreach {argl body} $g_moduleProcs($name) {}
reportDebug "execute-modulefile: Export module procedure $name"
interp eval $slave [list proc $name $argl $body]
}
foreach name [array names g_moduleVars] {
reportDebug "execute-modulefile: Export variable $name"
interp eval $slave [list set $name $g_moduleVars($name)]
}
}
set errorVal [interp eval $slave {
if {$g_debug} {
report "Sourcing $ModulesCurrentModulefile"
}
set sourceFailed [catch {source $ModulesCurrentModulefile} errorMsg]
set mode [module-info mode]
if {$mode eq "help"} {
if {[info procs "ModulesHelp"] eq "ModulesHelp"} {
ModulesHelp
} else {
reportWarning "Unable to find ModulesHelp in\
$ModulesCurrentModulefile."
}
set sourceFailed 0
}
if {$mode eq "display" \
&& [info procs "ModulesDisplay"] eq "ModulesDisplay"} {
ModulesDisplay
}
if {$sourceFailed} {
global errorInfo
# no error in case of "continue" command
if {$sourceFailed == 4} {
unset errorMsg
return 0
} elseif {$errorMsg eq "" && (![info exists errorInfo]\
|| $errorInfo eq "")} {
raiseErrorCount
unset errorMsg
return 1
}\
elseif [regexp "^WARNING" $errorMsg] {
raiseErrorCount
report $errorMsg
return 1
} else {
reportInternalBug "Occurred in file\
$ModulesCurrentModulefile:$errorInfo"
# return a specific value to provoke an exit after end
# of slave evaluation since here 'exit' procedure has
# been superseeded for modulefile interpretation
return 2
}
} else {
unset errorMsg
return 0
}
}]
interp delete $slave
reportDebug "Exiting $modfile"
# exits rather returns if a critical error has been raised
# and if the exit_on_error behavior is set
if {$errorVal == 2 && $exit_on_error} {
exitOnError
} else {
return $errorVal
}
}
# Smaller subset than main module load... This function runs modulerc and
# .version files
proc execute-modulerc {modfile {exit_on_error 1} {allow_exports {0}}} {
global g_rcfilesSourced ModulesVersion
global g_debug g_moduleDefault g_inhibit_errreport
global ModulesCurrentModulefile
reportDebug "execute-modulerc: $modfile"
set ModulesCurrentModulefile $modfile
set ModulesVersion {}
if {![checkValidModule $modfile]} {
reportInternalBug "Magic cookie '#%Module' missing in '$modfile'"
return ""
}
set modname [file dirname [currentModuleName]]
if {![info exists g_rcfilesSourced($modfile)]} {
reportDebug "execute-modulerc: sourcing rc $modfile"
set slave __.modulerc
if {![interp exists $slave]} {
interp create $slave
interp alias $slave uname {} uname
interp alias $slave system {} system
interp alias $slave chdir {} chdir
interp alias $slave module-version {} module-version
interp alias $slave module-alias {} module-alias
if {$allow_exports} {
interp alias $slave module-proc {} module-proc
interp alias $slave module-set {} module-set
}
interp alias $slave module {} module
interp alias $slave module-info {} module-info
interp alias $slave module-trace {} module-trace
interp alias $slave module-verbosity {} module-verbosity
interp alias $slave module-user {} module-user
interp alias $slave module-log {} module-log
interp alias $slave reportInternalBug {} reportInternalBug
interp alias $slave setModulesVersion {} setModulesVersion
interp eval $slave {global ModulesCurrentModulefile g_debug\
g_inhibit_errreport ModulesVersion}
interp eval $slave [list "set" "ModulesCurrentModulefile" $modfile]
interp eval $slave [list "set" "g_debug" $g_debug]
interp eval $slave [list "set" "g_inhibit_errreport"\
$g_inhibit_errreport]
interp eval $slave {set ModulesVersion {}}
}
set errorVal [interp eval $slave {
if [catch {source $ModulesCurrentModulefile} errorMsg] {
global errorInfo
reportInternalBug "Occurred in file\
$ModulesCurrentModulefile:$errorInfo"
# return a specific value to provoke an exit after end
# of slave evaluation
return 2
} else {
# pass ModulesVersion value to master interp
if {[info exists ModulesVersion]} {
setModulesVersion $ModulesVersion
}
return 0
}
}]
interp delete $slave
if {[file tail $modfile] eq ".version" && $ModulesVersion ne ""} {
# only set g_moduleDefault if .version file,
# otherwise any modulerc settings ala "module-version /xxx default"
# would get overwritten
set g_moduleDefault($modname) $ModulesVersion
reportDebug "execute-version: Setting g_moduleDefault($modname)\
$ModulesVersion"
}
# Keep track of rc files we already sourced so we don't run them again
set g_rcfilesSourced($modfile) $ModulesVersion
# exits rather returns if a critical error has been raised
# and if the exit_on_error behavior is set
if {$errorVal == 2 && $exit_on_error} {
exitOnError
}
}
return $g_rcfilesSourced($modfile)
}
########################################################################
# commands run from inside a module file
#
set ModulesCurrentModulefile {}
# Dummy procedures for commands available on C-version but not
# implemented here. These dummy procedures enables support for
# modulefiles using these commands while warning users these
# commands have no effect.
proc module-log {args} {
reportWarning "'module-log' command not implemented"
}
proc module-verbosity {args} {
reportWarning "'module-verbosity' command not implemented"
}
proc module-user {args} {
reportWarning "'module-user' command not implemented"
}
proc module-trace {args} {
reportWarning "'module-trace' command not implemented"
}
proc module-info {what {more {}}} {
global g_shellType g_shell tcl_platform
set mode [currentMode]
reportDebug "module-info: $what $more mode=$mode"
switch -- $what {
"mode" {
if {$more ne ""} {
set command [currentCommandName]
if {$mode eq $more || ($more eq "remove" && $mode eq "unload")\
|| ($more eq "switch" && $command eq "switch")} {
return 1
} else {
return 0
}
} else {
return $mode
}
}
"command" {
set command [currentCommandName]
if {$more eq ""} {
return $command
} elseif {$command eq $more} {
return 1
} else {
return 0
}
}
"name" {
return [currentModuleName]
}
"specified" {
return [currentSpecifiedName]
}
"shell" {
if {$more ne ""} {
if {$g_shell eq $more} {
return 1
} else {
return 0
}
} else {
return $g_shell
}
}
"flags" {
# C-version specific option, not relevant for Tcl-version but return
# a zero integer value to avoid breaking modulefiles using it
return 0
}
"shelltype" {
if {$more ne ""} {
if {$g_shellType eq $more} {
return 1
} else {
return 0
}
} else {
return $g_shellType
}
}
"user" {
# C-version specific option, not relevant for Tcl-version but return
# an empty value or false to avoid breaking modulefiles using it
if {$more ne ""} {
return 0
} else {
return {}
}
}
"alias" {
set ret [resolveModuleVersionOrAlias $more "alias"]
if {$ret ne $more} {
return $ret
} else {
return {}
}
}
"trace" {
return {}
}
"tracepat" {
return {}
}
"type" {
return "Tcl"
}
"symbols" {
return [join [getVersAliasList $more] ":"]
}
"version" {
lassign [getModuleNameVersion $more 1] mod
return [resolveModuleVersionOrAlias $mod]
}
default {
error "module-info $what not supported"
return {}
}
}
}
proc module-whatis {args} {
global g_whatis
set mode [currentMode]
set message [join $args " "]
reportDebug "module-whatis: $message mode=$mode"
if {$mode eq "display"} {
report "module-whatis\t$message"
}\
elseif {$mode eq "whatis"} {
lappend g_whatis $message
}
return {}
}
# Determine with a name provided as argument the corresponding module name,
# version and name/version. Module name is guessed from current module name
# when shorthand version notation is used. Both name and version are guessed
# from current module if name provided is empty. If 'default_is_special'
# argument is enabled then a 'default' version name is considered as a
# symbol not a filename (useful for module-version proc for instance)
proc getModuleNameVersion {{name {}} {default_is_special 0}} {
set curmod [currentModuleName]
set curmodname [file dirname $curmod]
set curmodversion [file tail $curmod]
if {$name eq ""} {
set name $curmodname
set version $curmodversion
# check for shorthand version notation like "/version" or "./version"
# only if we are currently interpreting a modulefile or modulerc
} elseif {$curmod ne "" && [regexp {^\.?\/(.*)$} $name match version]} {
# if we cannot distinguish a module name, raise error when
# shorthand version notation is used
global ModulesCurrentModulefile
if {$ModulesCurrentModulefile ne $curmod} {
# name is the name of current module directory
set name $curmodname
} else {
reportError "Invalid modulename '$name' found"
return {}
}
} else {
set version [file tail $name]
if {$name eq $version} {
set version ""
} else {
set name [file dirname $name]
# clear version if default
if {$version eq "default" && $default_is_special} {
set version ""
}
}
# name may correspond to last part of current module
# if so name is replaced by current module name
if {[file tail $curmodname] eq $name} {
set name $curmodname
}
}
if {$version eq ""} {
set mod $name
} else {
set mod $name/$version
}
return [list $mod $name $version]
}
# Specifies a default or alias version for a module that points to an
# existing module version Note that aliases defaults are stored by the
# short module name (not the full path) so aliases and defaults from one
# directory will apply to modules of the same name found in other
# directories.
proc module-version {args} {
global g_moduleVersion g_versionHash
global g_moduleDefault
global ModulesCurrentModulefile
reportDebug "module-version: executing module-version $args"
lassign [getModuleNameVersion [lindex $args 0] 1] mod modname modversion
foreach version [lrange $args 1 end] {
if {[string match $version "default"]} {
# If we see more than one default for the same module, just
# keep the first
if {![info exists g_moduleDefault($modname)]} {
set g_moduleDefault($modname) $modversion
reportDebug "module-version: default $modname = $modversion"
}
} else {
set aliasversion "$modname/$version"
reportDebug "module-version: alias $aliasversion = $mod"
if {![info exists g_moduleVersion($aliasversion)]} {
set g_moduleVersion($aliasversion) $mod
# don't add duplicates
if {![info exists g_versionHash($mod)] ||\
[lsearch -exact $g_versionHash($mod) $version] < 0} {
lappend g_versionHash($mod) $version
}
} else {
reportWarning "Duplicate version symbol '$version' found"
}
}
}
if {[string match [currentMode] "display"]} {
report "module-version\t$args"
}
return {}
}
proc module-alias {args} {
global g_moduleAlias g_aliasHash
global g_sourceAlias ModulesCurrentModulefile
lassign [getModuleNameVersion [lindex $args 0]] alias
lassign [getModuleNameVersion [lindex $args 1]] mod
reportDebug "module-alias: $alias = $mod"
set g_moduleAlias($alias) $mod
set g_aliasHash($mod) $alias
set g_sourceAlias($alias) $ModulesCurrentModulefile
if {[string match [currentMode] "display"]} {
report "module-alias\t$args"
}
return {}
}
proc module-proc {name args body} {
global g_moduleProcs
reportDebug "DEBUG module-proc: $name {$args}"
if {![info exists g_moduleProcs($name)]} {
set g_moduleProcs($name) [list $args $body]
#eval [list proc $name $args $body]
} else {
reportDebug "module-proc: duplicate $name"
}
}
proc module-set {name value} {
global g_moduleVars
reportDebug "module-set: $name"
if {![info exists g_moduleVars($name)]} {
set g_moduleVars($name) $value
}
}
proc module {command args} {
global show_oneperline
set mode [currentMode]
# guess if called from top level
set topcall [expr {[info level] == 1}]
if {$topcall} {
set msgprefix ""
} else {
set msgprefix "module: "
}
switch -regexp -- $command {
{^(add|lo)} {
if {[llength $args] == 0} {
set errormsg "Unexpected number of args for 'load' command"
} else {
pushCommandName "load"
if {$topcall || $mode eq "load"} {
eval cmdModuleLoad $args
}\
elseif {$mode eq "unload"} {
eval cmdModuleUnload $args
}\
elseif {$mode eq "display"} {
report "module load\t$args"
}
popCommandName
set needrender 1
}
}
{^(rm|unlo)} {
if {[llength $args] == 0} {
set errormsg "Unexpected number of args for 'unload' command"
} else {
pushCommandName "unload"
if {$topcall || $mode eq "load"} {
eval cmdModuleUnload $args
}\
elseif {$mode eq "unload"} {
eval cmdModuleUnload $args
}\
elseif {$mode eq "display"} {
report "module unload\t$args"
}
popCommandName
set needrender 1
}
}
{^(ref|rel)} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'reload' command"
} else {
pushCommandName "reload"
cmdModuleReload
popCommandName
set needrender 1
}
}
{^use$} {
if {$topcall || $mode eq "load"} {
eval cmdModuleUse $args
} elseif {$mode eq "unload"} {
eval cmdModuleUnuse $args
} elseif {$mode eq "display"} {
report "module use\t$args"
}
set needrender 1
}
{^unuse$} {
if {$topcall || $mode eq "load" || $mode eq "unload"} {
eval cmdModuleUnuse $args
} elseif {$mode eq "display"} {
report "module unuse\t$args"
}
set needrender 1
}
{^source$} {
if {[llength $args] == 0} {
set errormsg "Unexpected number of args for 'source' command"
} else {
pushCommandName "source"
eval cmdModuleSource $args
popCommandName
set needrender 1
}
}
{^sw} {
if {[llength $args] == 0 || [llength $args] > 2} {
set errormsg "Unexpected number of args for 'switch' command"
} else {
pushCommandName "switch"
eval cmdModuleSwitch $args
popCommandName
set needrender 1
}
}
{^(di|show)} {
if {[llength $args] == 0} {
set errormsg "Unexpected number of args for 'show' command"
} else {
pushCommandName "display"
foreach arg $args {
eval cmdModuleDisplay $arg
}
popCommandName
set needrender 1
}
}
{^av} {
pushCommandName "avail"
if {$args ne ""} {
foreach arg $args {
cmdModuleAvail $arg
}
} else {
cmdModuleAvail
}
popCommandName
}
{^al} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'aliases' command"
} else {
pushCommandName "aliases"
cmdModuleAliases
popCommandName
}
}
{^path$} {
if {[llength $args] != 1} {
set errormsg "Unexpected number of args for 'path' command"
} else {
eval cmdModulePath $args
set needrender 1
}
}
{^paths$} {
if {[llength $args] != 1} {
set errormsg "Unexpected number of args for 'paths' command"
} else {
eval cmdModulePaths $args
set needrender 1
}
}
{^li} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'list' command"
} else {
pushCommandName "list"
cmdModuleList
popCommandName
}
}
{^wh} {
pushCommandName "whatis"
if {$args ne ""} {
foreach arg $args {
cmdModuleWhatIs $arg
}
set needrender 1
} else {
cmdModuleWhatIs
}
popCommandName
}
{^(apropos|search|keyword)$} {
if {[llength $args] > 1} {
set errormsg "Unexpected number of args for '$command' command"
} else {
pushCommandName "search"
eval cmdModuleApropos $args
popCommandName
}
}
{^pu} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'purge' command"
} else {
pushCommandName "purge"
eval cmdModulePurge
popCommandName
set needrender 1
}
}
{^save$} {
if {[llength $args] > 1} {
set errormsg "Unexpected number of args for 'save' command"
} else {
eval cmdModuleSave $args
}
}
{^restore$} {
if {[llength $args] > 1} {
set errormsg "Unexpected number of args for 'restore' command"
} else {
pushCommandName "restore"
eval cmdModuleRestore $args
popCommandName
set needrender 1
}
}
{^saverm$} {
if {[llength $args] > 1} {
set errormsg "Unexpected number of args for 'saverm' command"
} else {
eval cmdModuleSaverm $args
}
}
{^saveshow$} {
if {[llength $args] > 1} {
set errormsg "Unexpected number of args for 'saveshow' command"
} else {
eval cmdModuleSaveshow $args
}
}
{^savelist$} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'savelist' command"
} else {
cmdModuleSavelist
}
}
{^init(add|lo)$} {
if {[llength $args] != 1} {
set errormsg "Unexpected number of args for 'initadd' command"
} else {
eval cmdModuleInit add $args
}
}
{^initprepend$} {
if {[llength $args] != 1} {
set errormsg "Unexpected number of args for 'initprepend' command"
} else {
eval cmdModuleInit prepend $args
}
}
{^initswitch$} {
if {[llength $args] != 2} {
set errormsg "Unexpected number of args for 'initswitch' command"
} else {
eval cmdModuleInit switch $args
}
}
{^init(rm|unlo)$} {
if {[llength $args] != 1} {
set errormsg "Unexpected number of args for 'initrm' command"
} else {
eval cmdModuleInit rm $args
}
}
{^initlist$} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'initlist' command"
} else {
eval cmdModuleInit list $args
}
}
{^initclear$} {
if {[llength $args] != 0} {
set errormsg "Unexpected number of args for 'initclear' command"
} else {
eval cmdModuleInit clear $args
}
}
{^debug$} {