Skip to content

Add subcmd_alias configuration option - #747

Open
xdelaruelle wants to merge 3 commits into
envmodules:mainfrom
xdelaruelle:issue712
Open

xdelaruelle wants to merge 3 commits into
envmodules:mainfrom
xdelaruelle:issue712

Conversation

@xdelaruelle

Copy link
Copy Markdown
Collaborator

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 definitions, e.g. find=avail:loaded=list. Sites set it in initrc, users with module config (including +/- to adjust the site definitions).

  • An alias may bear the name of an existing sub-command, which is then shadowed. This departs from what the issue asked for.
  • An alias target is always a sub-command of module (name, predefined alias or abbreviation), never another alias: definitions cannot be chained nor loop. With find=avail:avail=spider, find still runs avail.
  • Aliases apply to the module and ml command line only. module commands evaluated in modulefiles, rc files and initrc are not affected.
  • Alias names are restricted to letters, digits, _ and -, so completion scripts can safely handle them. Invalid definitions are ignored.
  • Defined aliases are listed at the end of the module help / module --help usage message.
  • bash, zsh and fish completion propose alias names and complete an alias like its target. tcsh completion rules being static, alias rules are generated when the completion script is sourced, so aliases defined later in a tcsh session are not completed.
  • Completion scripts clear MODULES_SUBCMD_ALIAS on their own module avail/spider/list/savelist/stashlist calls, 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

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>
Comment thread init/bash_completion.in

-*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );;
*) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") );;
*) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@$aliases" -- "$cur") );;
Comment thread init/bash_completion.in
_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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let users and sites define their own sub-command aliases

2 participants