Skip to content

Conversation

@gtristan
Copy link

@gtristan gtristan commented May 6, 2017

This addresses the issues outlined in #780

  • Changes the bash entry point to use "complete -o nospace"
  • Adds abstract method to ParamType allowing the parameters to participate in the completion
  • Migrates Choice completion implementation into types.py on the actual Choice type
  • Implement the completions() method for BoolParamType, File and Path parameter types too

This behaves all around much better:

  • No more completing of filenames when that is undesirable
  • Completes filenames or directories selectively, depending on the parameter

gtristan added 8 commits May 6, 2017 19:16
Allows parameter types to implement their own completions.
The -o default will cause the shell to complete paths in any
case that the program did not provide completions in COMPREPLY,
this is undesirable as it will result in completing filenames
when the next argument or option in context is not a filename.

We use nospace here so we can control whether to append a space
or not to the completions, this will allow us to complete paths
with python code and allow completing more dynamically (so that
after completing a subdirectory there is no space appended and
one can continue to complete the next subdir).
…tions

Instead of special casing the Choice type.

Note that this checks the user provided 'autocompletions' list in
advance of consulting the parameter class, this should allow users
to override the default completion list of a parameter.

Some minor adjustments made to append a space to builtin completion
lists of commands and option names so that this works seamlessly
with the new "complete -o nospace" approach.
Slightly changed semantic for the autocompletion function which can
be specified in a decorator, now point out the semantic difference of
appending a space to a returned completion suggestion or not.

This should not be an API break since the autocompletion function
was added recently and has never been in a stable/official release.
After changing the bash wrapping script to invoke complete with the
nospace option, the decision to append a space and decide to start
completing the next program argument falls on click. So now all
results from get_choices() which are entirely "complete" and cannot
be further completed have an appended space.

Updated test case to expect this behavior from get_choices().
@gtristan gtristan closed this May 8, 2017
@gtristan gtristan deleted the completion-work branch May 8, 2017 09:14
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant