diff options
author | Xin Li <delphij@google.com> | 2024-03-06 09:29:56 -0800 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2024-03-06 09:29:56 -0800 |
commit | 646563934a3e2ee26f50171f94d95173a1662e2c (patch) | |
tree | c1643be8ab17fc607cea748a8bb1d621a5964873 /pw_cli/py/pw_cli/__main__.py | |
parent | b1463ed3bc39c55c2a9496b8332940473fc3c023 (diff) | |
parent | 28d03a2a1cabbe01d7bcb6cf5166c10e50d3c2c6 (diff) | |
download | pigweed-646563934a3e2ee26f50171f94d95173a1662e2c.tar.gz |
Merge Android 14 QPR2 to AOSP main
Bug: 319669529
Merged-In: Icdf552029fb97a34e83c6dd7799433fc473a2506
Change-Id: I193fcbb5c284df7b04c8b6f860a61ffb6f521d37
Diffstat (limited to 'pw_cli/py/pw_cli/__main__.py')
-rw-r--r-- | pw_cli/py/pw_cli/__main__.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/pw_cli/py/pw_cli/__main__.py b/pw_cli/py/pw_cli/__main__.py index 3320a4556..363bc80a5 100644 --- a/pw_cli/py/pw_cli/__main__.py +++ b/pw_cli/py/pw_cli/__main__.py @@ -31,14 +31,33 @@ def main() -> NoReturn: pw_cli.log.install(level=args.loglevel, debug_log=args.debug_log) - # Start with the most critical part of the Pigweed command line tool. - if not args.no_banner: + # Print the banner unless --no-banner or --tab-complete-command is provided. + # Note: args.tab_complete_command may be the empty string '' so check for + # None instead. + if not args.no_banner and args.tab_complete_command is None: arguments.print_banner() _LOG.debug('Executing the pw command from %s', args.directory) os.chdir(args.directory) - pw_command_plugins.register(args.directory) + pw_command_plugins.register() + + if args.tab_complete_option is not None: + arguments.print_completions_for_option( + arguments.arg_parser(), + text=args.tab_complete_option, + tab_completion_format=args.tab_complete_format, + ) + sys.exit(0) + + if args.tab_complete_command is not None: + for name, plugin in sorted(pw_command_plugins.plugin_registry.items()): + if name.startswith(args.tab_complete_command): + if args.tab_complete_format == 'zsh': + print(':'.join([name, plugin.help()])) + else: + print(name) + sys.exit(0) if args.help or args.command is None: print(pw_command_plugins.format_help(), file=sys.stderr) |