Describe the use case
I would like to be able to plug custom commands that support the specifics of my project's alembic workflows.
A previous discussion suggested that subclassing CommandLine and extending it with custom logic is a good enough solution, and I agree with that. However, the whole initialization of the CLI, including the registration of commands, happens in the single CommandLine._generate_args - which makes it hard to add extra commands without duplicating the whole process or inventing inferior workarounds.
I would suggest to refactor the method and split it into smaller ones, with one of the parts being something called CommandLine._register_command. This would be still called internally to register commands from alembic.command but would also be available to subclasses to register other externally provided functions as commands.
Example Use
I would like to be able to define a subclass like so
class MyCommandLine(CommandLine):
def _generate_args(self, prog: str | None) -> None:
super()._generate_args(prog)
self._register_command(my_custom_command)
which would make my_custom_command immediately available in the cli.
Have a nice day!
Describe the use case
I would like to be able to plug custom commands that support the specifics of my project's alembic workflows.
A previous discussion suggested that subclassing
CommandLineand extending it with custom logic is a good enough solution, and I agree with that. However, the whole initialization of the CLI, including the registration of commands, happens in the singleCommandLine._generate_args- which makes it hard to add extra commands without duplicating the whole process or inventing inferior workarounds.I would suggest to refactor the method and split it into smaller ones, with one of the parts being something called
CommandLine._register_command. This would be still called internally to register commands fromalembic.commandbut would also be available to subclasses to register other externally provided functions as commands.Example Use
I would like to be able to define a subclass like so
which would make
my_custom_commandimmediately available in the cli.Have a nice day!