From db714cd72a548971644285e0c9e7b82ffdc79f6d Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 22 Jul 2024 11:16:35 +0200 Subject: [PATCH] app: Add -q argument for quiet mode Add a west argument to decrease the verbosity. Signed-off-by: Pieter De Gendt --- src/west/app/main.py | 26 +++++++++++++++++++++++--- src/west/commands.py | 9 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/west/app/main.py b/src/west/app/main.py index 4f8fc9d4..900958a8 100755 --- a/src/west/app/main.py +++ b/src/west/app/main.py @@ -97,6 +97,9 @@ def consume_more_args(rest): elif rest.startswith('v'): verbosity += 1 consume_more_args(rest[1:]) + elif rest.startswith('q'): + verbosity -= 1 + consume_more_args(rest[1:]) elif rest.startswith('z'): if not rest[1:]: expecting_zephyr_base = True @@ -121,8 +124,13 @@ def consume_more_args(rest): elif arg.startswith('-v'): verbosity += 1 consume_more_args(arg[2:]) + elif arg.startswith('-q'): + verbosity -= 1 + consume_more_args(arg[2:]) elif arg == '--verbose': verbosity += 1 + elif arg == '--quiet': + verbosity -= 1 elif arg.startswith('-z'): if arg == '-z': expecting_zephyr_base = True @@ -465,6 +473,10 @@ def make_parsers(self): help='''Display verbose output. May be given multiple times to increase verbosity.''') + parser.add_argument('-q', '--quiet', default=0, action='count', + help='''Display less verbose output. May be given + multiple times to decrease verbosity.''') + parser.add_argument('-V', '--version', action='version', version=f'West version: v{__version__}', help='print the program version and exit') @@ -594,8 +606,14 @@ def setup_west_logging(self, verbosity): logger.setLevel(logging.DEBUG) elif verbosity == 1: logger.setLevel(logging.INFO) - else: + elif verbosity == 0: logger.setLevel(logging.WARNING) + elif verbosity == -1: + logger.setLevel(logging.ERROR) + elif verbosity == -2: + logger.setLevel(logging.CRITICAL) + else: + logger.disabled = True logger.addHandler(LogHandler()) @@ -1070,8 +1088,10 @@ def mie_msg(mie): return ret def adjust_command_verbosity(command, args): - command.verbosity = min(command.verbosity + args.verbose, - Verbosity.DBG_EXTREME) + command.verbosity = max( + min(command.verbosity + args.verbose - args.quiet, Verbosity.DBG_EXTREME), + Verbosity.QUIET + ) def dump_traceback(): # Save the current exception to a file and return its path. diff --git a/src/west/commands.py b/src/west/commands.py index b1fe8b91..6f19dce9 100644 --- a/src/west/commands.py +++ b/src/west/commands.py @@ -422,6 +422,9 @@ def inf(self, *args, colorize: bool = False, end: str = '\n'): is undefined or true, and stdout is a terminal, then the message is printed in green. ''' + if Verbosity.INF > self.verbosity: + return + if not self.color_ui: colorize = False @@ -460,6 +463,9 @@ def wrn(self, *args, end: str = '\n'): :param args: sequence of arguments to print.''' + if Verbosity.WRN > self.verbosity: + return + if self.color_ui: print(WRN_COLOR, end='', file=sys.stderr) @@ -484,6 +490,9 @@ def err(self, *args, fatal: bool = False, end: str = '\n'): "FATAL ERROR: "; otherwise, "ERROR: " is used. ''' + if Verbosity.ERR > self.verbosity: + return + if self.color_ui: print(ERR_COLOR, end='', file=sys.stderr)