Skip to content

How can you create a plugin with subcommands? #8091

Closed Answered by mtkennerly
mtkennerly asked this question in Q&A
Discussion options

You must be logged in to vote

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:

class DebugInfoCommand(Command):
name = "debug info"

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!

$ poetry list
[...]
Available commands:
[...]
  config          …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mtkennerly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants