:param args: List of arguments, with the 'aws' removed. For example, the command "aws s3 list-objects --bucket foo" will have an args list of ``['s3', 'list-objects', '--bucket', 'foo']``.
(self, args=None)
| 575 | return parser |
| 576 | |
| 577 | def main(self, args=None): |
| 578 | """ |
| 579 | |
| 580 | :param args: List of arguments, with the 'aws' removed. For example, |
| 581 | the command "aws s3 list-objects --bucket foo" will have an |
| 582 | args list of ``['s3', 'list-objects', '--bucket', 'foo']``. |
| 583 | |
| 584 | """ |
| 585 | if args is None: |
| 586 | args = sys.argv[1:] |
| 587 | command_table = self._get_command_table() |
| 588 | parser = self.create_parser(command_table) |
| 589 | self._add_aliases(command_table, parser) |
| 590 | parsed_args = None |
| 591 | try: |
| 592 | # Because _handle_top_level_args emits events, it's possible |
| 593 | # that exceptions can be raised, which should have the same |
| 594 | # general exception handling logic as calling into the |
| 595 | # command table. This is why it's in the try/except clause. |
| 596 | parsed_args, remaining = parser.parse_known_args(args) |
| 597 | self._handle_top_level_args(parsed_args) |
| 598 | validate_preferred_output_encoding() |
| 599 | self._emit_session_event(parsed_args) |
| 600 | HISTORY_RECORDER.record('CLI_VERSION', self._cli_version(), 'CLI') |
| 601 | HISTORY_RECORDER.record('CLI_ARGUMENTS', args, 'CLI') |
| 602 | return command_table[parsed_args.command](remaining, parsed_args) |
| 603 | except BaseException as e: |
| 604 | # when --version action executed default argparser prints out |
| 605 | # version string and calls sys.exit(0) |
| 606 | if isinstance(e, SystemExit) and e.code == 0: |
| 607 | return e.code |
| 608 | LOG.debug("Exception caught in main()", exc_info=True) |
| 609 | return self._error_handler.handle_exception( |
| 610 | e, |
| 611 | stdout=get_stdout_text_writer(), |
| 612 | stderr=get_stderr_text_writer(), |
| 613 | parsed_globals=parsed_args, |
| 614 | ) |
| 615 | |
| 616 | def _emit_session_event(self, parsed_args): |
| 617 | # This event is guaranteed to run after the session has been |