-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add subcommand tab completion for data plugin commands #1035
add subcommand tab completion for data plugin commands #1035
Conversation
@ltalirz Feel free to reassign to v0.12.0 If you think this non-essential. |
It is worth mentioning that the previous behaviour was something like
|
Also, please let me know if you can think of a way to test tab completion on travis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, very good! I only added a couple of small comments/questions. It works ok for 'old' commands, I couldn't test with click commands, are there any in aiida_core that would trigger the new code, or they are all in plugins?
if isinstance(cmd_or_class, (click.Command, click.MultiCommand)): | ||
import sys | ||
from aiida.cmdline.commands import click_subcmd_complete | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why you take out the first 3 args and what is the content of sys.argv[4:len(sys.argv)-1]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested info is in the docstring of the function now.
aiida/cmdline/commands/__init__.py
Outdated
@click.group() | ||
@click.option('--profile', '-p') | ||
def verdi(profile): | ||
pass | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this command work? Is this a replacement for the Completion class in verdilib/when is this called? If this is the case (i.e. 'verdi completion' calls now this and not directly the Completion() class, , maybe we should move the Completion class out of verdilib, where it is automatically discovered (I'm assuming the autodiscover of the classes in verdilib is still active).
BTW, for the testing, one could try to use an approach similar/adapted from the one used in this package: https://github.com/kislyuk/argcomplete/blob/master/test/test.py |
There are no commands with which to test this currently in core. I used a data command i am developing in aiida-vasp to test it. |
ed37cb0
to
87eda2f
Compare
Rebased on release_v0.11.0 and adjusted the base of the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I am not sure if this should be in the release but it makes the recently added data plugin commands more user friendly, usage example:
The way it works is by inserting code in the current completion system that recognizes click commands and treats them specially:
All click type commands are actually invoked by invoking aiida.cmdline.commands.verdi (a click group).
Therefore I had to use sys.argv in the completion code to find the class of the actual subcommands in order to create a completion function for it using the
.listcommands
functionality that allclick.MultiCommands
have.It may look hackish but I don't see a much cleaner way without changing more about how the current completion system works.