def GetGsutilApiForTabComplete(self): """Builds and returns a gsutil_api based off gsutil_api_class_map_factory. Returns: the gsutil_api instance """ # This should match the support map for the "ls" command. support_map = { 'gs': [ApiSelector.XML, ApiSelector.JSON], 's3': [ApiSelector.XML] } default_map = {'gs': ApiSelector.JSON, 's3': ApiSelector.XML} gsutil_api_map = GsutilApiMapFactory.GetApiMap( self.gsutil_api_class_map_factory, support_map, default_map) gsutil_api = CloudApiDelegator(self.bucket_storage_uri_class, gsutil_api_map, self._GetTabCompleteLogger(), DiscardMessagesQueue(), debug=0) return gsutil_api
def ConfigureCommandArgumentParsers(self, subparsers): """Configures argparse arguments and argcomplete completers for commands. Args: subparsers: argparse object that can be used to add parsers for subcommands (called just 'commands' in gsutil) """ # This should match the support map for the "ls" command. support_map = { 'gs': [ApiSelector.XML, ApiSelector.JSON], 's3': [ApiSelector.XML] } default_map = {'gs': ApiSelector.JSON, 's3': ApiSelector.XML} gsutil_api_map = GsutilApiMapFactory.GetApiMap( self.gsutil_api_class_map_factory, support_map, default_map) logger = CreateGsutilLogger('tab_complete') gsutil_api = CloudApiDelegator(self.bucket_storage_uri_class, gsutil_api_map, logger, DiscardMessagesQueue(), debug=0) for command in set(self.command_map.values()): command_parser = subparsers.add_parser( command.command_spec.command_name, add_help=False) if isinstance(command.command_spec.argparse_arguments, dict): subcommand_parsers = command_parser.add_subparsers() subcommand_argument_dict = command.command_spec.argparse_arguments for subcommand, arguments in subcommand_argument_dict.iteritems( ): subcommand_parser = subcommand_parsers.add_parser( subcommand, add_help=False) self._ConfigureCommandArgumentParserArguments( subcommand_parser, arguments, gsutil_api) else: self._ConfigureCommandArgumentParserArguments( command_parser, command.command_spec.argparse_arguments, gsutil_api)