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

[question] How to force plumbum to process selected CLI switch first? #633

Open
vient opened this issue Feb 13, 2023 · 0 comments
Open

[question] How to force plumbum to process selected CLI switch first? #633

vient opened this issue Feb 13, 2023 · 0 comments

Comments

@vient
Copy link
Contributor

vient commented Feb 13, 2023

Hi, it may be easier to show in code what I mean:

import logging
from plumbum import cli

logging.basicConfig(level=logging.INFO)

class A(cli.Application):
    @cli.autoswitch()
    def debug(self):
        logging.basicConfig(level=logging.DEBUG, force=True)
        logging.debug('enabled debug logs')
    
    @cli.autoswitch()
    def another_option(self):
        logging.debug('enabled another option')

    def main(self, *args):
        logging.info('in main')

A.run()

when run produces

$ ./lul.py
INFO:root:in main

$ ./lul.py --debug --another-option
DEBUG:root:enabled debug logs
DEBUG:root:enabled another option
INFO:root:in main

$ ./lul.py --another-option --debug
DEBUG:root:enabled debug logs
INFO:root:in main

Options are clearly processed in the order they occur in command line but in this case I would prefer to scan command line first for --debug option since if affects logs from other switches. I tried to extract --debug option in separate class DebugOptionProcessor(cli.Application) class and then use class A(DebugOptionProcessor) but it did not change anything. Is it possible to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant