Output configuration¶
Configuration¶
Introduce options to define the content of the output:
avail_output: elements to report onavailsub-command regular modeavail_terse_output: elements to report onavailsub-command terse modeavail_json_output: elements to report onavailsub-command JSON modelist_output: elements to report onlistsub-command regular modelist_terse_output: elements to report onlistsub-command terse modelist_json_output: elements to report onlistsub-command JSON modespider_output: elements to report onspidersub-command regular modespider_terse_output: elements to report onspidersub-command terse modespider_json_output: elements to report onspidersub-command JSON mode
Specification¶
Output configuration is available
Output configuration is not available (but could be added later on)
Output configuration defines the content of the output not its format
These configurations are set by default with the elements reported by default
avail_output:modulepath:alias:dirwsym:sym:tag:variantifspec:keyavail_terse_output:modulepath:alias:dirwsym:sym:tag:variantifspecavail_json_output:modulepath:alias:dirwsym:sym:tag:vialist_output:header:idx:variant:sym:tag:keylist_terse_output:headerlist_json_output:variant:sym:tag:viaspider_output:modulepath:alias:dirwsym:sym:tag:variantifspec:via:keyspider_terse_output:modulepath:alias:dirwsym:sym:tag:variantifspecspider_json_output:modulepath:alias:dirwsym:sym:tag:via
The above default value could be superseded:
with an environment variable, that can be set through the use of the
configsub-commandMODULES_AVAIL_OUTPUTto supersedeavail_outputdefault valueMODULES_AVAIL_TERSE_OUTPUTto supersedeavail_terse_outputdefault valueMODULES_AVAIL_JSON_OUTPUTto supersedeavail_json_outputdefault valueMODULES_LIST_OUTPUTto supersedelist_outputdefault valueMODULES_LIST_TERSE_OUTPUTto supersedelist_terse_outputdefault valueMODULES_LIST_JSON_OUTPUTto supersedelist_json_outputdefault valueMODULES_SPIDER_OUTPUTto supersedespider_outputdefault valueMODULES_SPIDER_TERSE_OUTPUTto supersedespider_terse_outputdefault valueMODULES_SPIDER_JSON_OUTPUTto supersedespider_json_outputdefault value
with the
-o/--outputcommand-line optionwhich applies to the current output mode defined (regular, terse or JSON)
-o/--outputalso supersedes environment variable definition
Accepted elements in value lists are:
For
availregular and terse options: modulepath, alias, provided-alias, dirwsym, indesym, sym, tag, key, variant, variantifspec, hidden, via (only on regular output)For
availJSON option: modulepath, alias, provided-alias, dirwsym, sym, tag, variant, variantifspec, hidden, via, mtimeFor
listregular and terse options: header, idx, variant, alias, indesym, sym, tag, key, hiddenFor
listJSON option: variant, alias, sym, tag, hidden, via, mtimeFor
spiderregular and terse options: modulepath, alias, provided-alias, dirwsym, indesym, sym, tag, key, variant, variantifspec, hidden, via (only on regular output)For
spiderJSON option: modulepath, alias, provided-alias, dirwsym, sym, tag, variant, variantifspec, hidden, via, mtime
If the
-o/--outputoptions are wrongly specifiedAn error is raised and evaluation terminates
It may happen in the following situations
No value set after the option
Option set on unsupported module sub-command
Element set in option value unsupported by module sub-command
Elements set in option value not separated by colon character (
:)Option set on unsupported output format (
--long)The above situations apply whether command is called from the terminal or within a modulefile
For all these new configuration options
accepted value is a list of strings separated by colon character (
:)order of elements in the list does not matter
an empty string is a valid value (means only the modulefile name has to be reported)
If the
MODULES_AVAIL_OUTPUT/MODULES_AVAIL_TERSE_OUTPUT/MODULES_AVAIL_JSON_OUTPUT,MODULES_LIST_OUTPUT/MODULES_LIST_TERSE_OUTPUT/MODULES_LIST_JSON_OUTPUT,MODULES_SPIDER_OUTPUT/MODULES_SPIDER_TERSE_OUTPUT/MODULES_SPIDER_JSON_OUTPUTenv vars are wrongly specifiedTheir value is ignored
So the default value takes precedence, unless a
-o/--outputoption is specifiedValue in environment variable is wrongly specified for instance in the following situations
Element set in option value unsupported by module sub-command
Elements set in option value not separated by colon character (
:)
avail_outputsupersedesavail_report_dir_symandavail_report_mfile_symconfigurationsEnabled
avail_report_dir_symcorresponds to addingdirsymvalue toavail_outputEnabled
avail_report_mfile_symcorresponds to addingsymvalue toavail_outputBoth
avail_report_dir_symandavail_report_mfile_symcould be removed safely as:it was not possible to define them at configure time
or change default value with an environment variable
Some output content cannot be controlled at the moment with the output options:
Hidden modules is exclusively controlled by
--alloption to get these modules unveiledIndepth/no-indepth output is exclusively controlled by
--no-indepth/--indepthand related configuration option
When modulepath element is removed from an
availorspider-related optionall the modulefiles returned from all searched modulepaths are merged and sorted as a single set
a module appearing in several modulepaths is only reported once
tags or symbols applying to a lower priority module with same name are still reported
JSON output¶
Rationale
Each element in the JSON document is a cost: variant requires a scan evaluation of every modulefile, mtime requires to stat every modulefile when no module cache file is available
Default content is thus kept minimal to preserve response time and an output configuration lets user or site add the elements they need
Output configuration is applied to
--jsonmode through the same mechanisms as regular and terse modes (configuration option, environment variable and-o/--outputcommand-line option) rather than through dedicated options
The content of the JSON document is defined by the
<cmd>_json_outputconfiguration option relative to the sub-command runElements in these options select the JSON keys reported in each module object
The
-o/--outputoption applies to<cmd>_json_outputwhen--jsonmode is set,+and-prefixes are supported the same way as on regular and terse modes-o/--outputis still refused on--longmode
Some keys are intrinsic to the JSON objects and are always reported
nameandtypekeys on every objectpathnamekey onmodulefileobjectstargetkey onaliasobjectsWhen output configuration value is an empty string, module objects only hold these keys
Mapping between elements and the content of the JSON document
modulepath: top-level JSON object is keyed by modulepath, each value being an object keyed by module name (
availandspideronly)alias: objects of type
aliasare reportedprovided-alias: like alias plus the aliases provided by modulefiles, which requires a scan evaluation of every modulefile (
availandspideronly)dirwsym: objects of type
directoryare reported for directories associated with symbolic versions (availandspideronly)sym:
symbolskey is added tomodulefile,aliasanddirectoryobjectstag:
tagskey is added tomodulefileandaliasobjectsvariant:
variantskey is added tomodulefileobjectsVariants and their possible values on
availandspider, each value list being a JSON array of strings (onandofffor a Boolean variant,*denoting a free value variant)Variant values selected for loaded modules on
list
variantifspec: like variant but only if a variant has been specified in search query (
availandspideronly)hidden: hidden modules are reported, like on regular output mode
via:
viakey is added to every objectmtime:
mtimekey is added tomodulefileobjects
mtime is a new element specific to JSON output mode
It reports the modification time of the modulefile, like
--longmode does on text outputValue is a JSON string in ISO 8601 format with local time and UTC offset (
YYYY-MM-DDTHH:MM:SS±hhmm) to be both human-readable and parsable by JSON consumers without ambiguity, unlikeYYYY/MM/DD HH:MM:SSformat used on--longmodeNo
mtimekey is set onaliasanddirectoryobjects, like--longmode which reports no modification time for themValue is
nullif modification time cannot be fetched, for instance when the modulefile of a loaded module does not exist anymoreModification time of virtual modules is the one of the modulefile they point to
Modification time is only fetched when mtime element is enabled, as it requires to stat every modulefile when no module cache file is available (modification time is recorded in module cache files)
mtime is not accepted on regular and terse output modes as
--longmode already serves this purpose there
Elements not accepted on JSON output mode
key: no legend is reported on JSON output
header and idx (
list): JSON document has no introduction sentence and the position of a loaded module is its position in the top-level objectindesym: symbolic versions are already reported in the
symbolskey of the object they are attached to
When an element is not enabled, its corresponding key is omitted from the JSON objects rather than set to an empty value
A JSON consumer can tell from the document which elements were reported
Document is smaller when few elements are requested
When modulepath element is removed from an
availorspiderJSON optionTop-level JSON object is directly keyed by module name, like the
listsub-command JSON documentModules from the different modulepaths are merged as a single set, with the same rules as regular output mode (a module appearing in several modulepaths is only reported once)
Aliases defined in global/user rc are merged in this single set too
Default values of
avail_json_output,list_json_outputandspider_json_outputreproduce the JSON document produced prior to the introduction of these optionsExisting JSON consumers get the exact same document unless configuration is changed
variant is thus part of
list_json_outputdefault value but not ofavail_json_outputandspider_json_outputdefault valuesvia is part of
list_json_outputdefault value even if its value is currently always empty onlistsub-command (see spider sub-command design notes)
--alloption still unveils hidden modules on JSON output mode, like hidden element doesInstall-time options are added to change the default value of these configuration options
--with-avail-json-output--with-list-json-output--with-spider-json-output
Output key¶
An output key is added to print a legend explaining the output
Meaning of
(),{}or<>is explainedDefault version is colored specifically
Every tag shortened to a defined abbreviation
Every tag colored specifically
Every variant type set (
variant=value,+boolvariant,-boolvariant,%shortcutvariantvalue, etc)Legend entries only concern elements that can be found in reported output
Legend entries are not reported on JSON output mode
Output key is enabled by default on
avail,spiderandlistsub-command outputKey is reported at the end of the output
No key section is reported if no element need to be described (no color, no symbol, no tag, etc)
Variant keys are not adapted for
avail/spideroutputEven if all possible values are reported instead of the only one set
Users should be able to understand
name=val1,val2,...corresponds to thename=valuekey entrySame applies to the shortcut variant key