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

View file

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