forked from ungleich-public/cdist
Deprecate -d, make -v log level counter.
This commit is contained in:
parent
f473b671b1
commit
e7c3c15724
2 changed files with 25 additions and 10 deletions
|
@ -46,11 +46,12 @@ All commands accept the following options:
|
||||||
|
|
||||||
.. option:: -d, --debug
|
.. option:: -d, --debug
|
||||||
|
|
||||||
Set log level to debug
|
Set log level to debug (deprecated, use -vvv instead)
|
||||||
|
|
||||||
.. option:: -v, --verbose
|
.. option:: -v, --verbose
|
||||||
|
|
||||||
Set log level to info, be more verbose
|
Increase log level, be more verbose. The order of levels from lowest to
|
||||||
|
greatest are: ERROR, WARNING, INFO, DEBUG.
|
||||||
|
|
||||||
.. option:: -V, --version
|
.. option:: -V, --version
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import collections
|
||||||
|
import logging
|
||||||
|
|
||||||
# list of beta sub-commands
|
# list of beta sub-commands
|
||||||
BETA_COMMANDS = ['install', ]
|
BETA_COMMANDS = ['install', ]
|
||||||
|
@ -61,6 +63,15 @@ def check_beta(args_dict):
|
||||||
raise cdist.CdistBetaRequired(cmd, arg)
|
raise cdist.CdistBetaRequired(cmd, arg)
|
||||||
|
|
||||||
|
|
||||||
|
_verbosity_level = {
|
||||||
|
0: logging.ERROR,
|
||||||
|
1: logging.WARNING,
|
||||||
|
2: logging.INFO,
|
||||||
|
}
|
||||||
|
_verbosity_level = collections.defaultdict(
|
||||||
|
lambda: logging.DEBUG, _verbosity_level)
|
||||||
|
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -78,11 +89,14 @@ def commandline():
|
||||||
# Options _all_ parsers have in common
|
# Options _all_ parsers have in common
|
||||||
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
|
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
|
||||||
parser['loglevel'].add_argument(
|
parser['loglevel'].add_argument(
|
||||||
'-d', '--debug', help='Set log level to debug',
|
'-d', '--debug',
|
||||||
|
help=('Set log level to debug (deprecated, use -vvv instead)'),
|
||||||
action='store_true', default=False)
|
action='store_true', default=False)
|
||||||
parser['loglevel'].add_argument(
|
parser['loglevel'].add_argument(
|
||||||
'-v', '--verbose', help='Set log level to info, be more verbose',
|
'-v', '--verbose',
|
||||||
action='store_true', default=False)
|
help=('Increase log level, be more verbose. The order of levels '
|
||||||
|
'from lowest to greatest are: ERROR, WARNING, INFO, DEBUG.'),
|
||||||
|
action='count', default=0)
|
||||||
|
|
||||||
# Main subcommand parser
|
# Main subcommand parser
|
||||||
parser['main'] = argparse.ArgumentParser(
|
parser['main'] = argparse.ArgumentParser(
|
||||||
|
@ -179,11 +193,12 @@ def commandline():
|
||||||
|
|
||||||
args = parser['main'].parse_args(sys.argv[1:])
|
args = parser['main'].parse_args(sys.argv[1:])
|
||||||
|
|
||||||
# Loglevels are handled globally in here and debug wins over verbose
|
# Loglevels are handled globally in here
|
||||||
if args.verbose:
|
|
||||||
logging.root.setLevel(logging.INFO)
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
logging.root.setLevel(logging.DEBUG)
|
log.warning("-d/--debug is deprecated, use -vvv instead")
|
||||||
|
args.verbose = 3
|
||||||
|
|
||||||
|
logging.root.setLevel(_verbosity_level[args.verbose])
|
||||||
|
|
||||||
log.debug(args)
|
log.debug(args)
|
||||||
log.info("version %s" % cdist.VERSION)
|
log.info("version %s" % cdist.VERSION)
|
||||||
|
@ -219,7 +234,6 @@ if __name__ == "__main__":
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import cdist
|
import cdist
|
||||||
|
|
Loading…
Reference in a new issue