1 # Copyright 2020 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
14 """The Pigweed command line interface."""
19 from typing import NoReturn
22 from pw_cli import arguments, plugins
24 _LOG = logging.getLogger(__name__)
27 def main() -> NoReturn:
28 """Entry point for the pw command."""
30 args = arguments.parse_args()
33 pw_cli.log.set_level(args.loglevel)
35 # Start with the most critical part of the Pigweed command line tool.
36 if not args.no_banner:
37 arguments.print_banner()
39 _LOG.debug('Executing the pw command from %s', args.directory)
40 os.chdir(args.directory)
42 plugins.register(args.directory)
44 if args.help or args.command is None:
45 print(arguments.format_help(), file=sys.stderr)
49 sys.exit(plugins.run(args.command, args.plugin_args))
50 except plugins.Error as err:
51 _LOG.critical('Cannot run command %s.', args.command)
52 _LOG.critical('%s', err)
56 if __name__ == '__main__':