From 90ddc32d97838d024bd60ceec8f30f04b42aa7f3 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Fri, 7 Apr 2023 15:26:21 +0200 Subject: log: Make last of --debug/--quiet take precedence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- gemato/cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gemato/cli.py b/gemato/cli.py index 0047a5d..7c67a35 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -59,20 +59,20 @@ class GematoCommand: """ Add options specific to the command to subparser @subp. """ - subp.add_argument('--debug', action='store_true', + subp.add_argument("--debug", action="store_const", + dest="log_level", const=logging.DEBUG, + default=logging.INFO, help='Enable debugging output') - subp.add_argument('-q', '--quiet', action='store_true', - help='Only emit warning or error messages') + subp.add_argument("-q", "--quiet", action="store_const", + dest="log_level", const=logging.WARNING, + help="Only emit warning or error messages") def parse_args(self, args, argp): """ Process command-line arguments @args. @argp is the argparse instance provided for error reporting. """ - if args.debug: - logging.getLogger().setLevel(logging.DEBUG) - elif args.quiet: - logging.getLogger().setLevel(logging.WARNING) + logging.getLogger().setLevel(args.log_level) def __call__(self): """ @@ -115,7 +115,7 @@ class BaseOpenPGPMixin: env_class = OpenPGPEnvironment else: env_class = OpenPGPSystemEnvironment - self.openpgp_env = env_class(debug=args.debug, + self.openpgp_env = env_class(debug=args.log_level == logging.DEBUG, proxy=args.proxy) if args.openpgp_key is not None: -- cgit v1.2.3