Skip to content

CommandLine should be more easily extendable with custom commands #1610

@mikeroll

Description

@mikeroll

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    command interfaceuse casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions