add verbose support

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-09-27 17:20:31 +02:00
parent d8da7635de
commit 0e8dcb2f3d
1 changed files with 11 additions and 6 deletions

View File

@ -41,7 +41,11 @@ def commandline():
# Options _all_ parsers have in common
parser['most'] = argparse.ArgumentParser(add_help=False)
parser['most'].add_argument('-d', '--debug',
help='Set log level to debug', action='store_true')
help='Set log level to debug', action='store_true',
default=False)
parser['most'].add_argument('-v', '--verbose',
help='Set log level to info, is more verbose',
action='store_true', default=False)
# Main subcommand parser
parser['main'] = argparse.ArgumentParser(description='cdist ' + cdist.VERSION)
@ -87,12 +91,13 @@ def commandline():
args = parser['main'].parse_args(sys.argv[1:])
# Most subcommands have --debug, so handle it here
if 'debug' in args:
if args.debug:
logging.root.setLevel(logging.DEBUG)
log.debug(args)
# Loglevels are handled globally in here and debug wins over verbose
if args.verbose:
logging.root.setLevel(logging.INFO)
if args.debug:
logging.root.setLevel(logging.DEBUG)
log.debug(args)
args.func(args)
if __name__ == "__main__":