Skip to content
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

Allow handle() to be an initializer. #24

Closed
bckohan opened this issue Feb 29, 2024 · 0 comments
Closed

Allow handle() to be an initializer. #24

bckohan opened this issue Feb 29, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@bckohan
Copy link
Owner

bckohan commented Feb 29, 2024

Should be able to decorate handle() with initialize. This would allow you to do something like:

from click import get_current_context
from django_typer import TyperCommand, initialize, command


class Command(TyperCommand):
    
    @initialize(invoke_without_command=True)
    def handle(self):
        if (ctx := get_current_context(silent=True)) and ctx.invoked_subcommand:
            return
        
        # if we're here a subcommand was not invoked
        return 'handle'

    @command()
    def subcommand(self):
        return 'subcommand'

Which would allow:

./manage.py command
handle
./manage.py command subcommand
subcommand

And:

from django_typer import get_command

get_command('command')()
'handle'

You currently get an exception if you try to wrap handle in initialize(), which is a borderline bug.

@bckohan bckohan self-assigned this Feb 29, 2024
@bckohan bckohan added this to the Version 1.1 milestone Feb 29, 2024
@bckohan bckohan added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Mar 4, 2024
@bckohan bckohan removed this from the Version 1.1 milestone Mar 5, 2024
bckohan added a commit that referenced this issue Mar 5, 2024
@bckohan bckohan closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant