aboutsummaryrefslogtreecommitdiff
path: root/pw_cli
diff options
context:
space:
mode:
authorAlexei Frolov <frolv@google.com>2020-03-05 15:38:53 -0800
committerCQ Bot Account <commit-bot@chromium.org>2020-03-06 00:03:52 +0000
commit728048b8928b70335419d4d66942c27ffe1fc94b (patch)
treebeb36cc4f43321f36bfdfba1b64cfa01a8325d7f /pw_cli
parent613625ede174982d6aaf149d3c753dcaeeff4c3e (diff)
downloadpigweed-728048b8928b70335419d4d66942c27ffe1fc94b.tar.gz
pw_cli: Add argument to hide banner
This change adds an argument to the pw command which prevents it from printing the Pigweed banner. This is useful when pw is called from scripts to avoid polluting the output. Bug: 143 Change-Id: I30af43bd7815aa0472a1cb1ac2ca3f5ef49976dc
Diffstat (limited to 'pw_cli')
-rw-r--r--pw_cli/py/pw_cli/__main__.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/pw_cli/py/pw_cli/__main__.py b/pw_cli/py/pw_cli/__main__.py
index ffa5cfdba..e95c7d8ff 100644
--- a/pw_cli/py/pw_cli/__main__.py
+++ b/pw_cli/py/pw_cli/__main__.py
@@ -40,6 +40,13 @@ _PIGWEED_BANNER = '''
'''
+class ArgumentParser(argparse.ArgumentParser):
+ def error(self, message: str) -> None:
+ print(colors().magenta(_PIGWEED_BANNER), file=sys.stderr)
+ self.print_usage(sys.stderr)
+ self.exit(2, '%s: error: %s\n' % (self.prog, message))
+
+
def main(raw_args=None):
"""Entry point for pw command."""
@@ -49,15 +56,15 @@ def main(raw_args=None):
# TODO(keir): Add support for configurable logging levels.
pw_cli.log.install()
- # Start with the most critical part of the Pigweed command line tool.
- print(colors().magenta(_PIGWEED_BANNER))
-
# Add commands and their parsers.
- parser = argparse.ArgumentParser(
+ parser = ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--loglevel', default='INFO')
+ parser.add_argument('--no-banner',
+ action='store_true',
+ help="Don't print the Pigweed banner")
# Default command is 'help'
pw_cli.plugins.register(
@@ -96,6 +103,10 @@ def main(raw_args=None):
args = parser.parse_args(raw_args)
+ # Start with the most critical part of the Pigweed command line tool.
+ if not args.no_banner:
+ print(colors().magenta(_PIGWEED_BANNER))
+
args_as_dict = dict(vars(args))
del args_as_dict['_command']
del args_as_dict['_run_async']
@@ -106,6 +117,9 @@ def main(raw_args=None):
args_as_dict['loglevel'].upper()))
del args_as_dict['loglevel']
+ if 'no_banner' in args_as_dict:
+ del args_as_dict['no_banner']
+
# Run the command and exit with the appropriate status.
# pylint: disable=protected-access
if args._run_async: