From 179094989bc37f9369135733bab92d6477d7e0cb Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Mon, 9 Dec 2013 11:53:12 -0800 Subject: [PATCH] Don't require s3:// prefix on ls commands The path will always refer to an s3 object, so it's not necessary to specify s3://. Now we support both versions: * aws s3 ls s3://bucket-name * aws s3 ls bucket-name --- awscli/customizations/s3/s3.py | 5 ++++- tests/integration/customizations/s3/test_plugin.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/awscli/customizations/s3/s3.py b/awscli/customizations/s3/s3.py index 064d2c2e3bcb..4e8e6e02e214 100644 --- a/awscli/customizations/s3/s3.py +++ b/awscli/customizations/s3/s3.py @@ -342,7 +342,10 @@ def _get_endpoint(self, service, parsed_globals): class ListCommand(S3SubCommand): def _do_command(self, parsed_args, parsed_globals): - bucket, key = find_bucket_key(parsed_args.paths[0][5:]) + path = parsed_args.paths[0] + if path.startswith('s3://'): + path = path[5:] + bucket, key = find_bucket_key(path) self.service = self._session.get_service('s3') self.endpoint = self._get_endpoint(self.service, parsed_globals) if not bucket: diff --git a/tests/integration/customizations/s3/test_plugin.py b/tests/integration/customizations/s3/test_plugin.py index e4fe878dc5e3..fb95f0df43cd 100644 --- a/tests/integration/customizations/s3/test_plugin.py +++ b/tests/integration/customizations/s3/test_plugin.py @@ -534,6 +534,15 @@ def test_ls_recursive(self): self.assertIn('8 bar.txt', p.stdout) self.assertIn('8 subdir/foo.txt', p.stdout) + def test_ls_without_prefix(self): + # The ls command does not require an s3:// prefix, + # we're always listing s3 contents. + bucket_name = self.create_bucket() + self.put_object(bucket_name, 'foo.txt', 'contents') + p = aws('s3 ls %s' % bucket_name) + self.assertEqual(p.rc, 0) + self.assertIn('foo.txt', p.stdout) + class TestMbRb(BaseS3CLICommand): """