Skip to content

CommandLine should be more easily extendable with custom commands #1610

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

Closed
mikeroll opened this issue Feb 23, 2025 · 2 comments
Closed

CommandLine should be more easily extendable with custom commands #1610

mikeroll opened this issue Feb 23, 2025 · 2 comments
Labels
command interface use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@mikeroll
Copy link
Contributor

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!

@mikeroll mikeroll added requires triage New issue that requires categorization use case not quite a feature and not quite a bug, something we just didn't think of labels Feb 23, 2025
mikeroll added a commit to mikeroll/alembic that referenced this issue Feb 23, 2025
@mikeroll mikeroll changed the title CommandLine should be more easily extendable with custom command CommandLine should be more easily extendable with custom commands Feb 23, 2025
@CaselIT
Copy link
Member

CaselIT commented Feb 24, 2025

Hi,

I think it makes sense as a request, will look at the PR

@CaselIT CaselIT added command interface and removed requires triage New issue that requires categorization labels Feb 24, 2025
@sqla-tester
Copy link
Collaborator

Mikhail Bulash has proposed a fix for this issue in the main branch:

Refactor CommandLine command registration https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command interface use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants