Skip to content

Commit f4f492b

Browse files
committed
Support --terse option on whatis and search sub-commands
Now that whatis and search group module-whatis lines under a single module name and wrap them to the terminal width, scripts parsing their results have no stable one line per entry format to rely on anymore. Accept the --terse option on both sub-commands, as avail and list already do, to report each module-whatis line on its own output line prefixed by the module name. No padding is added before the module name and no wrapping is applied, so each line holds a complete entry. The modulepath is reported as a header line, like avail does in terse mode. JSON output is unchanged. Fixes #720 Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
1 parent fe5ef0c commit f4f492b

10 files changed

Lines changed: 90 additions & 32 deletions

File tree

‎NEWS.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Modules 5.8.0 (not yet released)
2222
each matching modulefile is reported once, followed by its
2323
:mfcmd:`module-whatis` lines wrapped to the terminal width. (fix issue
2424
#720)
25+
* Add support for the :option:`--terse` option on :subcmd:`whatis` and
26+
:subcmd:`search` sub-commands to get one output line per
27+
:mfcmd:`module-whatis` entry prefixed by module name, without wrapping or
28+
padding, and modulepath reported as a header line. (fix issue #720)
2529

2630

2731
.. _5.7 release notes:

‎doc/source/changes.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,11 @@ The following command line switches appeared on Modules 5.
914914

915915
Starting Modules 5.6, :subcmd:`spider` sub-command is supported.
916916

917+
:option:`--terse`
918+
919+
Starting Modules 5.8, :subcmd:`search` and :subcmd:`whatis` sub-commands are
920+
supported.
921+
917922
:option:`--default`, :option:`--latest`, :option:`--indepth`,
918923
:option:`--no-indepth`
919924

@@ -1066,6 +1071,9 @@ The following module sub-commands appeared on Modules 5.
10661071

10671072
Starting Modules 5.8, name of each matching modulefile is reported once,
10681073
followed by its :mfcmd:`module-whatis` lines wrapped to the terminal width.
1074+
The :option:`--terse` option reports each :mfcmd:`module-whatis` line on its
1075+
own output line prefixed by the module name, without wrapping or padding,
1076+
and the modulepath as a header line.
10691077

10701078
Environment
10711079
"""""""""""

‎doc/source/module.rst‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ switches are accepted:
645645

646646
.. option:: --terse, -t
647647

648-
Display :subcmd:`avail`, :subcmd:`list`, :subcmd:`savelist`, :subcmd:`spider`
649-
and :subcmd:`stashlist` output in short format.
648+
Display :subcmd:`avail`, :subcmd:`list`, :subcmd:`savelist`,
649+
:subcmd:`search`, :subcmd:`spider`, :subcmd:`stashlist` and :subcmd:`whatis`
650+
output in short format.
650651

651652
.. only:: html or latex
652653

@@ -659,6 +660,9 @@ switches are accepted:
659660
.. versionchanged:: 5.6
660661
Support for :subcmd:`spider` sub-command added
661662

663+
.. versionchanged:: 5.8
664+
Support for :subcmd:`search` and :subcmd:`whatis` sub-commands added
665+
662666
.. option:: --timer
663667

664668
Prints at the end of the output an evaluation of the total execution time of
@@ -2670,7 +2674,7 @@ Module Sub-Commands
26702674
``__init__`` or when no collection name is specified and no *default*
26712675
collection exists
26722676

2673-
.. subcmd:: search [-a] [-j] string
2677+
.. subcmd:: search [-a] [-t|-j] string
26742678

26752679
Seeks through the :mfcmd:`module-whatis` information of all *modulefiles*
26762680
for the specified *string*. All *module-whatis* information matching the
@@ -2679,7 +2683,10 @@ Module Sub-Commands
26792683

26802684
Name of each matching *modulefile* is reported once, followed by its
26812685
*module-whatis* lines. This text is wrapped to the terminal width and its
2682-
continuation lines are aligned under the start of the first line text.
2686+
continuation lines are aligned under the start of the first line text. With
2687+
the :option:`--terse` option, each *module-whatis* line is reported on its
2688+
own output line prefixed by the module name, without wrapping or padding,
2689+
and the modulepath is reported as a header line.
26832690

26842691
.. only:: html or latex
26852692

@@ -2695,7 +2702,9 @@ Module Sub-Commands
26952702

26962703
.. versionchanged:: 5.8
26972704
Module name is reported once with its *module-whatis* lines grouped
2698-
below and wrapped to terminal width
2705+
below and wrapped to terminal width; option
2706+
:option:`--terse`/:option:`-t` added to get one output line per
2707+
*module-whatis* line
26992708

27002709
.. subcmd:: sh-to-mod shell script [arg...]
27012710

@@ -3174,15 +3183,18 @@ Module Sub-Commands
31743183
:subcmd:`module use<use>` is called from the command-line or within an
31753184
initialization modulefile script
31763185

3177-
.. subcmd:: whatis [-a] [-j] [pattern...]
3186+
.. subcmd:: whatis [-a] [-t|-j] [pattern...]
31783187

31793188
Display the information set up by the :mfcmd:`module-whatis` commands inside
31803189
*modulefiles* matching *pattern*. *pattern* may contain wildcard characters.
31813190
If no *pattern* is specified, all :mfcmd:`module-whatis` lines will be shown.
31823191

31833192
Name of each matching *modulefile* is reported once, followed by its
31843193
*module-whatis* lines. This text is wrapped to the terminal width and its
3185-
continuation lines are aligned under the start of the first line text.
3194+
continuation lines are aligned under the start of the first line text. With
3195+
the :option:`--terse` option, each *module-whatis* line is reported on its
3196+
own output line prefixed by the module name, without wrapping or padding,
3197+
and the modulepath is reported as a header line.
31863198

31873199
The parameter *pattern* may also be a symbolic modulefile name or a
31883200
modulefile alias. It may also leverage a specific syntax to finely select
@@ -3212,7 +3224,9 @@ Module Sub-Commands
32123224

32133225
.. versionchanged:: 5.8
32143226
Module name is reported once with its *module-whatis* lines grouped
3215-
below and wrapped to terminal width
3227+
below and wrapped to terminal width; option
3228+
:option:`--terse`/:option:`-t` added to get one output line per
3229+
*module-whatis* line
32163230

32173231

32183232
Modulefiles

‎init/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ comp_stashlist_opts := -j -l -t --json --long --terse
137137
comp_clear_opts := --force -f
138138
comp_avail_opts := -a -C -d -i -j -L -l -o -S -t --all --contains --default --icase --json --latest --long --output --output= --starts-with --terse --indepth --no-indepth
139139
comp_mfile_opts := -i --icase
140-
comp_whatis_opts := -a -i -j --all --icase --json
141-
comp_search_opts := -a -j --all --json
140+
comp_whatis_opts := -a -i -j -t --all --icase --json --terse
141+
comp_search_opts := -a -j -t --all --json --terse
142142
comp_aliases_opts := -a --all
143143
comp_use_opts := -a --append -p --prepend
144144
comp_isavail_opts := -i --icase

‎init/zsh-functions/_module.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,14 @@ _module() {
381381
(whatis)
382382
_arguments \
383383
'(-i --icase)'{-i,--icase}'[Case insensitive match]' \
384+
'(-t --terse)'{-t,--terse}'[Display output in terse format]' \
384385
'(-j --json)'{-j,--json}'[Display output in JSON format]' \
385386
'(-a --all)'{-a,--all}'[Include hidden modules in search]' \
386387
"*::modulefile:{_module_avail_mods $cur}" && ret=0
387388
;;
388389
(apropos|keyword|search)
389390
_arguments \
391+
'(-t --terse)'{-t,--terse}'[Display output in terse format]' \
390392
'(-j --json)'{-j,--json}'[Display output in JSON format]' \
391393
'(-a --all)'{-a,--all}'[Include hidden modules in search]' \
392394
&& ret=0

‎tcl/report.tcl.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,9 +2100,9 @@ Listing / Searching commands:
21002100
[-i] [--indepth|--no-indepth] [mod ...]
21012101
List all or matching available modules
21022102
aliases [-a] List all module aliases
2103-
whatis [-a] [-i] [-j] [modulefile ...]
2103+
whatis [-a] [-i] [-j|-t] [modulefile ...]
21042104
Print whatis information of modulefile(s)
2105-
apropos | keyword | search [-a] [-j] str
2105+
apropos | keyword | search [-a] [-j|-t] str
21062106
Search all name and whatis containing str
21072107
spider [-a] [-t|-l|-j] [-S|-C] [-d|-L] [-o LIST]
21082108
[-i] [--indepth|--no-indepth] [mod ...]

‎tcl/subcmd.tcl.in‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ proc cmdModuleSearch {args} {
217217
set mod_pattern_list [lassign $args search]
218218

219219
set json [isStateEqual report_format json]
220+
set terse [isStateEqual report_format terse]
220221
set icase [isIcase]
221222

222223
lappend searchmod rc_defs_included
@@ -399,32 +400,41 @@ proc cmdModuleSearch {args} {
399400
whatis a $::g_whatis 1]
400401
} else {
401402
set eltsgr [string map $matchmodmap $elt]
402-
set eltpad [string repeat { } [expr {20 - [string length\
403-
$elt]}]]
403+
# one line per whatis entry, each prefixed by module name
404+
if {$terse} {
405+
foreach line $::g_whatis {
406+
set linesgr [string map $matchsearchmap $line]
407+
lappend display_list "$eltsgr: $linesgr"
408+
}
404409
# module name on first line only, whatis text of next lines
405410
# aligned under first line text and wrapped to term width
406-
set text_col [expr {[tcl::mathfunc::max 20 [string length\
407-
$elt]] + 2}]
408-
set text_pad [string repeat { } $text_col]
409-
set text_len [tcl::mathfunc::max [expr {[getState\
410-
term_columns] - $text_col}] 1]
411-
set first 1
412-
foreach entry $::g_whatis {
413-
foreach line [wrapTextToWidth [string map\
414-
$matchsearchmap $entry] $text_len] {
415-
if {$first} {
416-
set first 0
417-
lappend display_list "$eltpad$eltsgr: $line"
418-
} else {
419-
lappend display_list $text_pad$line
411+
} else {
412+
set eltpad [string repeat { } [expr {20 - [string length\
413+
$elt]}]]
414+
set text_col [expr {[tcl::mathfunc::max 20 [string\
415+
length $elt]] + 2}]
416+
set text_pad [string repeat { } $text_col]
417+
set text_len [tcl::mathfunc::max [expr {[getState\
418+
term_columns] - $text_col}] 1]
419+
set first 1
420+
foreach entry $::g_whatis {
421+
foreach line [wrapTextToWidth [string map\
422+
$matchsearchmap $entry] $text_len] {
423+
if {$first} {
424+
set first 0
425+
lappend display_list "$eltpad$eltsgr: $line"
426+
} else {
427+
lappend display_list $text_pad$line
428+
}
420429
}
421430
}
422431
}
423432
}
424433
}
425434
}
426435

427-
displayElementList $dir mp sepline 1 0 0 $display_list
436+
displayElementList $dir mp [expr {$terse ? {terse} : {sepline}}] 1\
437+
0 0 $display_list
428438
}
429439
}
430440
lpopState mode

‎testsuite/modules.70-maint/055-whatis.exp‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,20 @@ testouterr_cmd_re "csh" "-w 30 whatis $module_8" "OK" "$header\n$module_8: modul
9191
testouterr_cmd_re "csh" "-w 10 whatis $module_8" "OK" "$header\n$module_8: module\n${text_pad_8}version\n${text_pad_8}sort\n${text_pad_8}test"
9292
testouterr_cmd_re "csh" "-w 1 whatis $module_8" "OK" "$header\n$module_8: module\n${text_pad_8}version\n${text_pad_8}sort\n${text_pad_8}test"
9393

94-
# json output
94+
# terse output mode: one line per whatis entry, each prefixed by module name
95+
# without padding nor wrapping, modulepath reported as header line
96+
set header_t "$modpathre:"
97+
set ts_csh_5t "$header_t\n$module_5: Testsuite Whatis Modulefile\n$module_5: Second line of whatis tokens"
98+
testouterr_cmd_re "csh" "--terse whatis $module_5" "OK" "$ts_csh_5t"
99+
testouterr_cmd_re "csh" "-t whatis $module_5 $module_2" "OK" "$ts_csh_5t\n$module_2: Testsuite-Modulefile"
100+
testouterr_cmd_re "csh" "whatis -t $module_8" "OK" "$header_t\n$module_8: module version sort test"
101+
testouterr_cmd_re "csh" "-w 30 -t whatis $module_8" "OK" "$header_t\n$module_8: module version sort test"
102+
testouterr_cmd_re "csh" "-t whatis $module_1" "OK" "$ts_csh_1"
103+
104+
# json output is not affected by terse mode
95105
set ts_json_5 "{\"$modpathre\": {\n\"$module_5\": { \"name\": \"$module_5\", \"whatis\": \\\[ \"Testsuite Whatis Modulefile\", \"Second line of whatis tokens\" \\\]}\n}}"
96106
testouterr_cmd_re "csh" "-j whatis $module_5" "OK" "$ts_json_5"
107+
testouterr_cmd_re "csh" "-t -j whatis $module_5" "OK" "$ts_json_5"
97108

98109
# setup MODULEPATH with a trailing slash and an empty dir element
99110
setenv_path_var MODULEPATH {} "$modpath/"

‎testsuite/modules.70-maint/060-apropos.exp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ testouterr_cmd_re "csh" "apropos token" "ERR" "$header\n$ts_1\n$ts_1a"
7272
testouterr_cmd_re "csh" "keyword token" "ERR" "$header\n$ts_1\n$ts_1a"
7373
testouterr_cmd_re "csh" "search token" "ERR" "$header\n$ts_1\n$ts_1a"
7474

75+
# terse output mode: one line per whatis entry, each prefixed by module name
76+
# without padding nor wrapping, modulepath reported as header line
77+
set header_t "$modpathre:"
78+
set ts_1t "whatis/lines: Testsuite Whatis Modulefile\nwhatis/lines: Second line of whatis tokens"
79+
testouterr_cmd_re "csh" "-t search token" "ERR" "$header_t\n$ts_1t"
80+
testouterr_cmd_re "csh" "search -t token" "ERR" "$header_t\n$ts_1t"
81+
testouterr_cmd_re "csh" "-w 45 -t search Whatis" "ERR" "$header_t\n$ts_1t\nwhatis/multiple: Testsuite Whatis Modulefile\nwhatis/string: Testsuite Whatis Modulefile"
82+
7583
# text is wrapped to terminal width
7684
testouterr_cmd_re "csh" "-w 45 search Whatis" "ERR" "$header\n whatis/lines: Testsuite Whatis\n${text_pad}Modulefile\n${text_pad}Second line of whatis\n${text_pad}tokens\n whatis/multiple: Testsuite Whatis\n${text_pad}Modulefile\n whatis/string: Testsuite Whatis\n${text_pad}Modulefile"
7785

@@ -83,6 +91,7 @@ set nohi [sgr 22]
8391
set header_sgr "$modlin [sgr {1;94}]$modpathre[sgr 0] $modlin"
8492
testouterr_cmd_re "csh" "-w 49 search token" "ERR" "$header_sgr\n whatis/lines: Testsuite Whatis Modulefile\n${text_pad}Second line of whatis\n${text_pad}${hi}token${nohi}s"
8593
testouterr_cmd_re "csh" "-w 50 search token" "ERR" "$header_sgr\n whatis/lines: Testsuite Whatis Modulefile\n${text_pad}Second line of whatis ${hi}token${nohi}s"
94+
testouterr_cmd_re "csh" "-w 49 -t search token" "ERR" "[sgr {1;94}]$modpathre[sgr 0]:\nwhatis/lines: Testsuite Whatis Modulefile\nwhatis/lines: Second line of whatis ${hi}token${nohi}s"
8695
setenv_var MODULES_COLOR never
8796
unsetenv_var MODULES_COLORS
8897

‎testsuite/modules.70-maint/240-icase.exp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ testouterr_cmd sh {avail -i -t nOcAsE/vi} OK "$mp:\nnocase/virt"
161161
testouterr_cmd sh {avail -i -t NOCASE/Dee} OK "$mp:\nnocase/deep/(dirsym)\nnocase/deep/2\nnocase/deep/3"
162162
testouterr_cmd sh {avail -i -t NOcaSe2} OK "$mp:\nnocase2"
163163
testouterr_cmd sh {avail -i -t NOcase3} OK "$mp:\nnocase3(@)"
164-
testouterr_cmd_re sh {whatis -i -t noCASE/aL*} OK "$modlin $mpre $modlin\n\\s+nocase/1: nocase/1"
164+
testouterr_cmd_re sh {whatis -i -t noCASE/aL*} OK "$mpre:\nnocase/1: nocase/1"
165165
testouterr_cmd sh {paths -i noCASE/VE*} [list [list text $mp/nocase/1]] {}
166166
testouterr_cmd sh {whatis -i -t noCASE/aL} ERR $err_path'noCASE/aL'
167167
testouterr_cmd sh {paths -i noCASE/VE} OK {}
@@ -174,7 +174,7 @@ testouterr_cmd_re sh {whatis -i noCASE/.hiDden} OK "$modlin $mpre $modlin\n\\s+n
174174

175175
# add a bit of wildcard characters in specification
176176
testouterr_cmd sh {avail -i -t nOcAsE/vi?} OK "$mp:\nnocase/virt"
177-
testouterr_cmd_re sh {whatis -i -t noCASE/a*L*} OK "$modlin $mpre $modlin\n\\s+nocase/1: nocase/1"
177+
testouterr_cmd_re sh {whatis -i -t noCASE/a*L*} OK "$mpre:\nnocase/1: nocase/1"
178178
testouterr_cmd sh {whatis -i -t noCASE/a*L} ERR $err_path'noCASE/a*L'
179179
testouterr_cmd sh {paths -i noCASE/V*E?} OK {}
180180
testouterr_cmd sh {paths -i noCASE/V*E*} [list [list text $mp/nocase/1]] {}

0 commit comments

Comments
 (0)