Repository navigation
Add subcmd_alias configuration option - #747
Open
xdelaruelle wants to merge 3 commits into
Open
xdelaruelle wants to merge 3 commits into
xdelaruelle wants to merge 3 commits into
Conversation
People using several tools side by side expect the same action to bear the same name in each of them, but sub-command names and their aliases are fixed in module code. Add the subcmd_alias configuration option, superseded by the MODULES_SUBCMD_ALIAS environment variable, to define additional names for module sub-commands as a colon-separated list of alias=target elements. An alias may bear the name of an existing sub-command, which is then shadowed. Alias target is resolved among the sub-commands known by module and never among the defined aliases, so an alias cannot designate another alias and definitions cannot loop. Aliases are translated where the command line is parsed. module commands evaluated in modulefiles are not affected: their meaning does not depend on the configuration of who loads them. Alias names are restricted to letters, digits, underscore and hyphen-minus to let shell completion scripts safely handle them. Defined aliases are listed at the end of the usage message. Fixes envmodules#712 Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Shell completion scripts only know the sub-command names they are built with. An alias defined in the subcmd_alias configuration option was not proposed as a sub-command and did not get the modules or options of its target as candidates. Read alias definitions from the MODULES_SUBCMD_ALIAS environment variable in bash, zsh and fish completion scripts: propose alias names and translate the sub-command word into its target before selecting the candidates to return. tcsh completion rules are static, so alias rules are derived from the rule of their target when the completion script is sourced. Definitions whose name or target is made of unexpected characters are skipped, like module does, as these words are passed to shell constructs that expand them. Completion scripts call the avail, spider, list, savelist and stashlist sub-commands to fetch candidates. Clear alias definitions on these calls to get the expected sub-command even when its name is shadowed by an alias. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Describe in a design note how sub-command aliases are validated, resolved, scoped to the command line and handled by shell completion. Add a cookbook recipe that maps the command names of the Spack package manager onto module sub-commands with the subcmd_alias configuration option, as a complete example of this option. Refer to it from the option description and MIGRATING document. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
|
|
||
| -*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );; | ||
| *) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") );; | ||
| *) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@$aliases" -- "$cur") );; |
| _module_comgen_words "@comp_load_opts@ $loaded_modules" "$cur";; | ||
| *) _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur" | ||
| COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") ) | ||
| COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@$aliases" -- "$cur") ) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the
subcmd_aliasconfiguration option (superseded by theMODULES_SUBCMD_ALIASenvironment variable) to define additional names formodulesub-commands, as a colon-separated list ofalias=targetdefinitions, e.g.find=avail:loaded=list. Sites set it ininitrc, users withmodule config(including+/-to adjust the site definitions).module(name, predefined alias or abbreviation), never another alias: definitions cannot be chained nor loop. Withfind=avail:avail=spider,findstill runsavail.moduleandmlcommand line only.modulecommands evaluated in modulefiles, rc files and initrc are not affected._and-, so completion scripts can safely handle them. Invalid definitions are ignored.module help/module --helpusage message.MODULES_SUBCMD_ALIASon their ownmodule avail/spider/list/savelist/stashlistcalls, to still get the expected result when one of these names is shadowed.Documentation includes a design note and a cookbook recipe mapping the command names of the Spack package manager (
find=avail,list=spider,location=path, ...).Fixes #712