-
Notifications
You must be signed in to change notification settings - Fork 161
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
Pluggable Cli Commands #1938
Pluggable Cli Commands #1938
Conversation
✅ Deploy Preview for dlt-hub-docs canceled.
|
subparsers.add_parser("telemetry", help="Shows telemetry status") | ||
# install available commands | ||
installed_commands: Dict[str, SupportsCliCommand] = {} | ||
for c in commands: |
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.
each plugin gets instantiated and registered with the main parser, overwriting of existing commands is prevented. This approach is quite safe, but it will not allow to modify existing parsers or subparsers, this is to be discussed.
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.
I'd like to be able to overwrite init command with my own. this prevents that? IMO we should allow rewriting
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.
I do not think it is implemented. IMO you should first deduplicate command list, keeping the last occurence. It is better not to add overwritten subparsers to the parser
import argparse | ||
|
||
|
||
class SupportsCliCommand(Protocol): |
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.
Cli command interface
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.
hmmm this should go to cli
module, ie. to where you keep the hook definition. this is a place for injectable contexts
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.
please add a cli to dlt test plugin that adds commands and overwrites existing. tests are already set up.
should we have a module that imports all hooks? for the benefit of plugin makers that then can see all hooks are "external" protocols. we ourselves do not need to import it.
otherwise this is pretty good. let's do PR soon :)
subparsers.add_parser("telemetry", help="Shows telemetry status") | ||
# install available commands | ||
installed_commands: Dict[str, SupportsCliCommand] = {} | ||
for c in commands: |
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.
I'd like to be able to overwrite init command with my own. this prevents that? IMO we should allow rewriting
import argparse | ||
|
||
|
||
class SupportsCliCommand(Protocol): |
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.
hmmm this should go to cli
module, ie. to where you keep the hook definition. this is a place for injectable contexts
8375e76
to
88760b1
Compare
@rudolfix the requests are adressed. With regards to: |
* add tests for cli plugin discovery * allow plugins to overwrite core cli commands
f90a694
to
143b412
Compare
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.
this is really good! pls. drop the WIP
only thing to consider: deduplicate commands before adding them to parser.
subparsers.add_parser("telemetry", help="Shows telemetry status") | ||
# install available commands | ||
installed_commands: Dict[str, SupportsCliCommand] = {} | ||
for c in commands: |
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.
I do not think it is implemented. IMO you should first deduplicate command list, keeping the last occurence. It is better not to add overwritten subparsers to the parser
installed_commands: Dict[str, SupportsCliCommand] = {} | ||
for c in commands: | ||
command = c() | ||
command_parser = subparsers.add_parser(command.command, help=command.help_string) |
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.
here... what if we overwrite command
?
Description
This PR adds a plugin interface for CLI commands and converts all the existing commands to plugins.
General Notes:
TODOs before merge: