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?
Hi, it may be easier to show in code what I mean:
when run produces
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 separateclass DebugOptionProcessor(cli.Application)
class and then useclass A(DebugOptionProcessor)
but it did not change anything. Is it possible to do?