##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.00-init/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	initialization of the shell environment
#   Command:
#   Sub-Command:
#
#   Comment:	%C{
#			First time initialization: Remove everything from
#                       environment, that depends on the module package.
#			Select the 'empty' modulerc file
#		}C%
#
##############################################################################

if { $verbose > 0 } {
    send_user "\tInitializing the modulecmd environment ...\n"
}

# clear testsuite-related variables
foreach var [concat [array names env -glob TESTSUITE_*]\
    [list TESTSUITE TS0 TS1 TS2 TS3 TS4 TS4 TS6 TS7 TS8 TS9]] {
    # preserve variable externally set to configure testsuite run
    if {$var ne {TESTSUITE_ENABLE_SITECONFIG}} {
        unsetenv_var $var
    }
}

catch {unset env(MODULEPATH)}
catch {unset env(LOADEDMODULES)}
catch {unset env(_LMFILES_)}

catch {unset env(MODULES_LMCONFLICT)}
catch {unset env(MODULES_LMPREREQ)}
catch {unset env(MODULES_LMNOTUASKED)}
catch {unset env(MODULES_LMALTNAME)}
catch {unset env(MODULES_LMTAG)}
catch {unset env(MODULES_LMVARIANT)}

catch {unset env(MODULECONTACT)}

catch {unset env(MODULES_RUN_QUARANTINE)}

foreach var [array names env] {
    if {[string match "*_modshare" $var] \
        || [string match "*_modquar" $var] \
        || [string match "MODULES_RUNENV_*" $var]} {
        catch {unset env($var)}
    }
}

# clean any automated handling mode configuration
catch {unset env(MODULES_AUTO_HANDLING)}

# ensure tests are run with implicit requirement enabled
setenv_var MODULES_IMPLICIT_REQUIREMENT 1

# clean any in depth mode configuration
catch {unset env(MODULES_AVAIL_INDEPTH)}

# clean any unload match order config
catch {unset env(MODULES_UNLOAD_MATCH_ORDER)}

# clean any implicit default config
catch {unset env(MODULES_IMPLICIT_DEFAULT)}

# clean any search match config
catch {unset env(MODULES_SEARCH_MATCH)}

# clean any set shell startup config
catch {unset env(MODULES_SET_SHELL_STARTUP)}

# clean any shells defined to get ksh fpath set
catch {unset env(MODULES_SHELLS_WITH_KSH_FPATH)}
catch {unset env(FPATH)}
catch {unset env(FPATH_modshare)}

# clean any pager configuration
catch {unset env(LESS)}
catch {unset env(PAGER)}
catch {unset env(MODULES_PAGER)}

# ensure tests are run with a regular default verbosity level
setenv_var MODULES_VERBOSITY normal

# ensure tests are run with extended_default disabled by default
setenv_var MODULES_EXTENDED_DEFAULT 0

# clean any advanced version spec config
unsetenv_var MODULES_ADVANCED_VERSION_SPEC

# clean any nearly forbidden days config
unsetenv_var MODULES_NEARLY_FORBIDDEN_DAYS

# clean any tag abbreviation list
unsetenv_var MODULES_TAG_ABBREV

# clear specific tag name color setup
setenv_var MODULES_TAG_COLOR_NAME {}

# enable magic cookie version check by default
setenv_var MODULES_MCOOKIE_VERSION_CHECK 1

# ensure expected default output
setenv_var MODULES_AVAIL_OUTPUT {modulepath:alias:dirwsym:sym:tag:key}
setenv_var MODULES_AVAIL_TERSE_OUTPUT {modulepath:alias:dirwsym:sym:tag}
setenv_var MODULES_LIST_OUTPUT {header:idx:variant:sym:tag:key}
setenv_var MODULES_LIST_TERSE_OUTPUT {header}

# clean any variant config
setenv_var MODULES_VARIANT_SHORTCUT {}

# clean any editor config
unsetenv_var MODULES_EDITOR
unsetenv_var VISUAL
unsetenv_var EDITOR

# clean any additional siteconfig set
catch {unset env(MODULES_SITECONFIG)}

# clean any color configuration
catch {unset env(MODULES_COLORS)}
catch {unset env(MODULES_TERM_BACKGROUND)}
catch {unset env(NO_COLOR)}
catch {unset env(CLICOLOR)}
catch {unset env(CLICOLOR_FORCE)}
# ensure colored output is disabled by default
setenv_var MODULES_COLOR never

# clean any collection configuration
catch {unset env(MODULES_COLLECTION_PIN_VERSION)}
catch {unset env(MODULES_COLLECTION_TARGET)}

# clean any versioning configuration
catch {unset env(MODULE_VERSION)}
catch {unset env(MODULE_VERSION_STACK)}

set env(MODULERCFILE) "$env(TESTSUITEDIR)/etc/empty"
set ORIG_MODULERCFILE $env(MODULERCFILE)
catch {unset env(MODULESHOME)}

set ORIG_PATH $env(PATH)

unsetenv_var testsuite

