How can you create a plugin with subcommands? #8091
-
I haven't quite managed to figure this out from the Poetry or Cleo docs. I'd like to update my plugin to allow usage like this:
Is this supported? Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This issue led me to this example. It's a bit old but hopefully the API hasn't changed too much. |
Beta Was this translation helpful? Give feedback.
-
I wasn't able to make that example work, unfortunately, but thank you for the suggestion. I did have the idea to check how Poetry's own subcommands work, and I noticed this: poetry/src/poetry/console/commands/debug/info.py Lines 8 to 9 in 6e94298 So for a Poetry plugin, that looks like this: class DynamicVersioningEnableCommand(Command):
name = "dynamic-versioning enable"
# ...
application.command_loader.register_factory(
"dynamic-versioning enable", lambda: DynamicVersioningEnableCommand(application)
) And it works!
The only downside (in my opinion) is that |
Beta Was this translation helpful? Give feedback.
I wasn't able to make that example work, unfortunately, but thank you for the suggestion.
I did have the idea to check how Poetry's own subcommands work, and I noticed this:
poetry/src/poetry/console/commands/debug/info.py
Lines 8 to 9 in 6e94298
So for a Poetry plugin, that looks like this:
And it works!