Skip to content

Commit add05b0

Browse files
committed
Add value kind attribute in config option definition array
Update configuration option definition array (g_config_defs) to add value kind attribute as 4th entry in definition list. This attribute has following possible values: 'i' for integer, 's' for string, 'b' for boolean, 'l' for colon-separated list, 'o' for other.
1 parent e67b24b commit add05b0

File tree

5 files changed

+78
-72
lines changed

5 files changed

+78
-72
lines changed

doc/source/design/add-new-config-option.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ value then branch code in :file:`modulecmd.tcl` script to adapt
2929
- Superseding environment variable
3030
- Default value
3131
- Is configuration lockable to default value (0 or 1)
32+
- Value kind (``i`` for integer, ``s`` for string, ``b`` for boolean,
33+
``l`` for colon-separated list, ``o`` for other)
3234
- Valid value list (empty list if no validation list)
3335
- Internal value representation (optional)
3436
- Specific procedure to call to initialize option value (optional)

tcl/init.tcl.in

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -61,81 +61,84 @@ array set g_state_defs [list\
6161
]
6262

6363
# Configuration option properties (superseding environment variable, default
64-
# value, is configuration lockable to default value, valid value list?,
65-
# internal value representation?, proc to call to initialize option value,
66-
# valid value list kind
67-
##nagelfar ignore #64 Too long line
64+
# value, is configuration lockable to default value, value kind, valid value
65+
# list?, internal value representation?, proc to call to initialize option
66+
# value, valid value list kind
67+
##nagelfar ignore #73 Too long line
6868
array set g_config_defs [list\
69-
contact {MODULECONTACT root@localhost 0}\
70-
auto_handling {MODULES_AUTO_HANDLING @autohandling@ 0 {0 1}}\
71-
avail_indepth {MODULES_AVAIL_INDEPTH @availindepth@ 0 {0 1}}\
72-
avail_output {MODULES_AVAIL_OUTPUT {@availoutput@} 0 {modulepath alias\
69+
contact {MODULECONTACT root@localhost 0 s}\
70+
auto_handling {MODULES_AUTO_HANDLING @autohandling@ 0 b {0 1}}\
71+
avail_indepth {MODULES_AVAIL_INDEPTH @availindepth@ 0 b {0 1}}\
72+
avail_output {MODULES_AVAIL_OUTPUT {@availoutput@} 0 l {modulepath alias\
7373
dirwsym sym tag key variant variantifspec} {} {} eltlist}\
74-
avail_terse_output {MODULES_AVAIL_TERSE_OUTPUT {@availterseoutput@} 0\
74+
avail_terse_output {MODULES_AVAIL_TERSE_OUTPUT {@availterseoutput@} 0 l\
7575
{modulepath alias dirwsym sym tag key variant variantifspec} {} {}\
7676
eltlist}\
77-
cache_buffer_bytes {MODULES_CACHE_BUFFER_BYTES 32768 0 {4096 1000000} {}\
77+
cache_buffer_bytes {MODULES_CACHE_BUFFER_BYTES 32768 0 i {4096 1000000} {}\
7878
{} intbe}\
79-
cache_expiry_secs {MODULES_CACHE_EXPIRY_SECS 0 0 {0 31536000} {} {} intbe}\
80-
collection_pin_version {MODULES_COLLECTION_PIN_VERSION 0 0 {0 1}}\
81-
collection_pin_tag {MODULES_COLLECTION_PIN_TAG 0 0 {0 1}}\
82-
collection_target {MODULES_COLLECTION_TARGET <undef> 0}\
83-
color {MODULES_COLOR @color@ 0 {never auto always} {0 1 2} initConfColor}\
84-
colors {MODULES_COLORS {} 0 {} {} initConfColors}\
85-
csh_limit {{} 4000 0}\
86-
extra_siteconfig {MODULES_SITECONFIG <undef> 1 {}}\
87-
editor {MODULES_EDITOR {@editor@} 0 {} {} initConfEditor}\
88-
home {MODULESHOME {@moduleshome@} 0}\
89-
icase {MODULES_ICASE @icase@ 0 {never search always}}\
90-
ignore_cache {MODULES_IGNORE_CACHE 0 0 {0 1}}\
91-
ignore_user_rc {MODULES_IGNORE_USER_RC 0 0 {0 1}}\
92-
ignored_dirs {{} {CVS RCS SCCS .svn .git .SYNC .sos} 0}\
79+
cache_expiry_secs {MODULES_CACHE_EXPIRY_SECS 0 0 i {0 31536000} {} {}\
80+
intbe}\
81+
collection_pin_version {MODULES_COLLECTION_PIN_VERSION 0 0 b {0 1}}\
82+
collection_pin_tag {MODULES_COLLECTION_PIN_TAG 0 0 b {0 1}}\
83+
collection_target {MODULES_COLLECTION_TARGET <undef> 0 s}\
84+
color {MODULES_COLOR @color@ 0 s {never auto always} {0 1 2}\
85+
initConfColor}\
86+
colors {MODULES_COLORS {} 0 l {} {} initConfColors}\
87+
csh_limit {{} 4000 0 i}\
88+
extra_siteconfig {MODULES_SITECONFIG <undef> 1 s {}}\
89+
editor {MODULES_EDITOR {@editor@} 0 s {} {} initConfEditor}\
90+
home {MODULESHOME {@moduleshome@} 0 s}\
91+
icase {MODULES_ICASE @icase@ 0 s {never search always}}\
92+
ignore_cache {MODULES_IGNORE_CACHE 0 0 b {0 1}}\
93+
ignore_user_rc {MODULES_IGNORE_USER_RC 0 0 b {0 1}}\
94+
ignored_dirs {{} {CVS RCS SCCS .svn .git .SYNC .sos} 0 o}\
9395
implicit_requirement {MODULES_IMPLICIT_REQUIREMENT @implicitrequirement@ 0\
94-
{0 1}}\
95-
list_output {MODULES_LIST_OUTPUT {@listoutput@} 0 {header idx variant sym\
96-
tag key} {} {} eltlist}\
97-
list_terse_output {MODULES_LIST_TERSE_OUTPUT {@listterseoutput@} 0 {header\
98-
idx variant sym tag key} {} {} eltlist}\
99-
locked_configs {{} {@lockedconfigs@} 0}\
100-
mcookie_check {MODULES_MCOOKIE_CHECK always 0 {eval always}}\
96+
b {0 1}}\
97+
list_output {MODULES_LIST_OUTPUT {@listoutput@} 0 l {header idx variant\
98+
sym tag key} {} {} eltlist}\
99+
list_terse_output {MODULES_LIST_TERSE_OUTPUT {@listterseoutput@} 0 l\
100+
{header idx variant sym tag key} {} {} eltlist}\
101+
locked_configs {{} {@lockedconfigs@} 0 o}\
102+
mcookie_check {MODULES_MCOOKIE_CHECK always 0 s {eval always}}\
101103
mcookie_version_check {MODULES_MCOOKIE_VERSION_CHECK\
102-
@mcookieversioncheck@ 0 {0 1}}\
103-
ml {MODULES_ML @ml@ 0 {0 1}}\
104+
@mcookieversioncheck@ 0 b {0 1}}\
105+
ml {MODULES_ML @ml@ 0 b {0 1}}\
104106
nearly_forbidden_days {MODULES_NEARLY_FORBIDDEN_DAYS @nearlyforbiddendays@\
105-
0 {0 365} {} {} intbe}\
106-
pager {MODULES_PAGER {@pagercmd@} 0}\
107-
protected_envvars {MODULES_PROTECTED_ENVVARS <undef> 0}\
108-
rcfile {MODULERCFILE <undef> 0}\
109-
redirect_output {MODULES_REDIRECT_OUTPUT 1 0 {0 1}}\
110-
reset_target_state {MODULES_RESET_TARGET_STATE __init__ 0}\
111-
quarantine_support {MODULES_QUARANTINE_SUPPORT @quarantinesupport@ 0 {0\
107+
0 i {0 365} {} {} intbe}\
108+
pager {MODULES_PAGER {@pagercmd@} 0 s}\
109+
protected_envvars {MODULES_PROTECTED_ENVVARS <undef> 0 l}\
110+
rcfile {MODULERCFILE <undef> 0 s}\
111+
redirect_output {MODULES_REDIRECT_OUTPUT 1 0 b {0 1}}\
112+
reset_target_state {MODULES_RESET_TARGET_STATE __init__ 0 s}\
113+
quarantine_support {MODULES_QUARANTINE_SUPPORT @quarantinesupport@ 0 b {0\
112114
1}}\
113-
run_quarantine {MODULES_RUN_QUARANTINE <undef> 0}\
114-
shells_with_ksh_fpath {MODULES_SHELLS_WITH_KSH_FPATH {} 0 {sh bash csh\
115+
run_quarantine {MODULES_RUN_QUARANTINE <undef> 0 o}\
116+
shells_with_ksh_fpath {MODULES_SHELLS_WITH_KSH_FPATH {} 0 l {sh bash csh\
115117
tcsh fish} {} {} eltlist}\
116-
silent_shell_debug {MODULES_SILENT_SHELL_DEBUG @silentshdbgsupport@ 0 {0\
118+
silent_shell_debug {MODULES_SILENT_SHELL_DEBUG @silentshdbgsupport@ 0 b {0\
117119
1}}\
118-
siteconfig {{} {@etcdir@/siteconfig.tcl} 0}\
119-
tag_abbrev {MODULES_TAG_ABBREV {@tagabbrev@} 0 {} {} initConfTagAbbrev}\
120-
tag_color_name {MODULES_TAG_COLOR_NAME {@tagcolorname@} 0 {} {}\
120+
siteconfig {{} {@etcdir@/siteconfig.tcl} 0 s}\
121+
tag_abbrev {MODULES_TAG_ABBREV {@tagabbrev@} 0 l {} {} initConfTagAbbrev}\
122+
tag_color_name {MODULES_TAG_COLOR_NAME {@tagcolorname@} 0 l {} {}\
121123
initConfTagColorName}\
122-
tcl_ext_lib {{} {} 0 {} {} initConfTclExtLib}\
123-
tcl_linter {MODULES_TCL_LINTER {@tcllintercmd@} 0}\
124-
term_background {MODULES_TERM_BACKGROUND @termbg@ 0 {dark light}}\
125-
term_width {MODULES_TERM_WIDTH 0 0 {0 1000} {} {} intbe}\
126-
unload_match_order {MODULES_UNLOAD_MATCH_ORDER @unloadmatchorder@ 0\
124+
tcl_ext_lib {{} {} 0 s {} {} initConfTclExtLib}\
125+
tcl_linter {MODULES_TCL_LINTER {@tcllintercmd@} 0 s}\
126+
term_background {MODULES_TERM_BACKGROUND @termbg@ 0 s {dark light}}\
127+
term_width {MODULES_TERM_WIDTH 0 0 i {0 1000} {} {} intbe}\
128+
unload_match_order {MODULES_UNLOAD_MATCH_ORDER @unloadmatchorder@ 0 s\
127129
{returnlast returnfirst}}\
128-
implicit_default {MODULES_IMPLICIT_DEFAULT @implicitdefault@ 1 {0 1}}\
129-
extended_default {MODULES_EXTENDED_DEFAULT @extendeddefault@ 0 {0 1}}\
130-
advanced_version_spec {MODULES_ADVANCED_VERSION_SPEC @advversspec@ 0 {0\
130+
implicit_default {MODULES_IMPLICIT_DEFAULT @implicitdefault@ 1 b {0 1}}\
131+
extended_default {MODULES_EXTENDED_DEFAULT @extendeddefault@ 0 b {0 1}}\
132+
advanced_version_spec {MODULES_ADVANCED_VERSION_SPEC @advversspec@ 0 b {0\
131133
1}}\
132-
search_match {MODULES_SEARCH_MATCH @searchmatch@ 0 {starts_with contains}}\
133-
set_shell_startup {MODULES_SET_SHELL_STARTUP @setshellstartup@ 0 {0 1}}\
134-
variant_shortcut {MODULES_VARIANT_SHORTCUT {@variantshortcut@} 0 {} {}\
134+
search_match {MODULES_SEARCH_MATCH @searchmatch@ 0 s {starts_with\
135+
contains}}\
136+
set_shell_startup {MODULES_SET_SHELL_STARTUP @setshellstartup@ 0 b {0 1}}\
137+
variant_shortcut {MODULES_VARIANT_SHORTCUT {@variantshortcut@} 0 l {} {}\
135138
initConfVariantShortcut}\
136-
verbosity {MODULES_VERBOSITY @verbosity@ 0 {silent concise normal verbose\
137-
verbose2 trace debug debug2}}\
138-
wa_277 {MODULES_WA_277 @wa277@ 0 {0 1}}\
139+
verbosity {MODULES_VERBOSITY @verbosity@ 0 s {silent concise normal\
140+
verbose verbose2 trace debug debug2}}\
141+
wa_277 {MODULES_WA_277 @wa277@ 0 b {0 1}}\
139142
]
140143

141144
# Get state value
@@ -245,8 +248,8 @@ proc isConfigLocked {option} {
245248
proc getConf {option {valifundef {}}} {
246249
if {![info exists ::g_configs($option)]} {
247250
# fetch option properties (including its default value)
248-
lassign $::g_config_defs($option) envvar value islockable validvallist\
249-
intvallist initproc validvallistkind
251+
lassign $::g_config_defs($option) envvar value islockable valuekind\
252+
validvallist intvallist initproc validvallistkind
250253

251254
# ensure option is not locked before superseding its default value
252255
if {!$islockable || ![isConfigLocked $option]} {
@@ -757,9 +760,9 @@ proc initConfVariantShortcut {envvar value validvallist intvallist} {
757760

758761
# Is currently set verbosity level is equal or higher than level passed as arg
759762
proc isVerbosityLevel {name} {
760-
return [expr {[lsearch -exact [lindex $::g_config_defs(verbosity) 3]\
763+
return [expr {[lsearch -exact [lindex $::g_config_defs(verbosity) 4]\
761764
[getConf verbosity]] >= [lsearch -exact [lindex\
762-
$::g_config_defs(verbosity) 3] $name]}]
765+
$::g_config_defs(verbosity) 4] $name]}]
763766
}
764767

765768
# Is match performed in a case sensitive or insensitive manner

tcl/main.tcl.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ proc parseModuleCommandArgs {topcall cmd ignerr args} {
308308

309309
# check option value is coherent with current sub-command
310310
if {[isDiffBetweenList [split $asked_output :] [lindex\
311-
$::g_config_defs($outputconf) 3]]} {
311+
$::g_config_defs($outputconf) 4]]} {
312312
if {!$ignerr} {
313313
knerror "Invalid element in value list for '$output_arg'\
314314
option on $cmd sub-command\nAllowed elements are: [lindex\
315-
$::g_config_defs($outputconf) 3] (separated by ':')"
315+
$::g_config_defs($outputconf) 4] (separated by ':')"
316316
}
317317
} else {
318318
##nagelfar ignore Suspicious variable name
@@ -977,7 +977,7 @@ if {[catch {
977977
set asked_color [string range $arg 8 end]
978978
if {$asked_color eq {}} {
979979
set asked_color always
980-
} elseif {$asked_color ni [lindex $::g_config_defs(color) 3]} {
980+
} elseif {$asked_color ni [lindex $::g_config_defs(color) 4]} {
981981
unset asked_color
982982
}
983983
}
@@ -1095,7 +1095,7 @@ if {[catch {
10951095
--help' for more information."
10961096
}
10971097
if {[info exists asked_term_width]} {
1098-
set rangewidth [lindex $::g_config_defs(term_width) 3]
1098+
set rangewidth [lindex $::g_config_defs(term_width) 4]
10991099
if {[string is integer -strict $::asked_term_width] && \
11001100
$::asked_term_width >= [lindex $rangewidth 0] &&\
11011101
$::asked_term_width <= [lindex $rangewidth 1]} {

tcl/subcmd.tcl.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,8 @@ proc cmdModuleConfig {dump_state args} {
23162316

23172317
foreach option [array names ::g_config_defs] {
23182318
lassign $::g_config_defs($option) confvar($option) defval\
2319-
conflockable($option) confvalid($option) vtrans initproc\
2320-
confvalidkind($option)
2319+
conflockable($option) confkind($option) confvalid($option) vtrans\
2320+
initproc confvalidkind($option)
23212321
set confval($option) [getConf $option <undef>]
23222322
set confvtrans($option) {}
23232323
for {set i 0} {$i < [llength $vtrans]} {incr i} {
@@ -2334,6 +2334,7 @@ proc cmdModuleConfig {dump_state args} {
23342334
set confvar($runenvconf) $runenvvar
23352335
set confvalid($runenvconf) {}
23362336
set conflockable($runenvconf) {}
2337+
set confkind($runenvconf) s
23372338
set confvtrans($runenvconf) {}
23382339
set confvalidkind($runenvconf) {}
23392340
}

testsuite/example/siteconfig.tcl-1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,12 @@ if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_UNKINTERRDURINGMODEVAL)]} {
374374

375375
# set a bad value for tag_abbrev default value
376376
if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BADTAGABBREVDFLVALUE)]} {
377-
set g_config_defs(tag_abbrev) {MODULES_TAG_ABBREV {loaded} 0 {} {} initConfTagAbbrev}
377+
set g_config_defs(tag_abbrev) {MODULES_TAG_ABBREV {loaded} 0 l {} {} initConfTagAbbrev}
378378
}
379379

380380
# set a bad value for variant_shortcut default value
381381
if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BADVARIANTSHORTCUTDFLVALUE)]} {
382-
set g_config_defs(variant_shortcut) {MODULES_VARIANT_SHORTCUT {foo} 0 {} {} initConfVariantShortcut}
382+
set g_config_defs(variant_shortcut) {MODULES_VARIANT_SHORTCUT {foo} 0 l {} {} initConfVariantShortcut}
383383
}
384384

385385
# specific tests to improve getModuleDesignation procs coverage

0 commit comments

Comments
 (0)