diff --git a/awscli/customizations/s3/s3.py b/awscli/customizations/s3/s3.py index cd8fba468a72..0f0509a97983 100644 --- a/awscli/customizations/s3/s3.py +++ b/awscli/customizations/s3/s3.py @@ -181,10 +181,14 @@ def _create_subcommand_table(self): for cmd in CMD_DICT.keys(): cmd_specification = CMD_DICT[cmd] cmd_class = cmd_specification.get('command_class', S3SubCommand) - + # If a cmd_class is provided, the we'll try to grab the + # description and usage off of that object, otherwise + # we'll look in the command dict. + description, usage = self._get_command_usage(cmd_class) subcommand_table[cmd] = cmd_class( cmd, self._session, cmd_specification['options'], - cmd_specification['description'], cmd_specification['usage']) + cmd_specification.get('description', description), + cmd_specification.get('usage', usage)) self._session.emit('building-operation-table.%s' % self._name, operation_table=subcommand_table, @@ -194,6 +198,10 @@ def _create_subcommand_table(self): arg_table=None) return subcommand_table + def _get_command_usage(self, cmd_class): + return (getattr(cmd_class, 'DESCRIPTION', None), + getattr(cmd_class, 'USAGE', None)) + def create_help_command(self): """ This function returns a help command object with a filled command @@ -210,6 +218,8 @@ class S3SubCommand(object): """ This is the object corresponding to a S3 subcommand. """ + DESCRIPTION = None + USAGE = None def __init__(self, name, session, options, documentation="", usage=""): """ @@ -399,6 +409,31 @@ def _make_size_str(self, size): return size_str.rjust(10, ' ') +class WebsiteCommand(S3SubCommand): + DESCRIPTION = 'Create website configuration for an S3 bucket' + USAGE = 'Usage?' + + def _do_command(self, parsed_args, parsed_globals): + service = self._session.get_service('s3') + endpoint = service.get_endpoint(parsed_globals.region) + operation = service.get_operation('PutBucketWebsite') + bucket = self._get_bucket_name(parsed_args.paths[0]) + website_configuration = {} + # operation.call(endpoint, bucket=bucket, website_configuration=website_configuration) + + def _get_bucket_name(self, path): + # We support either: + # s3://bucketname + # bucketname + # + # We also strip off the trailing slash if a user + # accidently appends a slash. + if path.startswith('s3://'): + path = path[5:] + if path.endswith('/'): + path = path[:-1] + return path + class S3Parameter(BaseCLIArgument): """ @@ -773,7 +808,10 @@ def check_region(self, parsed_globals): 'params': [], 'default': 's3://', 'command_class': ListCommand}, 'mb': {'options': {'nargs': 1}, 'params': []}, - 'rb': {'options': {'nargs': 1}, 'params': ['force']} + 'rb': {'options': {'nargs': 1}, 'params': ['force']}, + 'website': {'options': {'nargs': 1}, + 'params': ['index-document', 'error-document'], + 'command_class': WebsiteCommand}, } add_command_descriptions(CMD_DICT) @@ -812,6 +850,7 @@ def check_region(self, parsed_globals): 'content-encoding': {'options': {'nargs': 1}}, 'content-language': {'options': {'nargs': 1}}, 'expires': {'options': {'nargs': 1}}, + 'index-document': {'options': {}, 'documents': 'The foo of bar.'}, + 'error-document': {'options': {}, 'documents': 'The bar of foo.'}, } - add_param_descriptions(PARAMS_DICT)