Skip to content

Commit 48b2b45

Browse files
committed
Allow top level commands to be renamed
Also adding tests to verify this.
1 parent 2d9025e commit 48b2b45

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

awscli/clidriver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ def create_help_command(self):
321321
return ServiceHelpCommand(session=self.session,
322322
obj=service_object,
323323
command_table=command_table,
324-
arg_table=None)
324+
arg_table=None,
325+
event_class='Operation',
326+
name=self._name)
325327

326328
def _create_parser(self):
327329
command_table = self._get_command_table()

awscli/help.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,20 @@ class ServiceHelpCommand(HelpCommand):
237237

238238
EventHandlerClass = ServiceDocumentEventHandler
239239

240+
def __init__(self, session, obj, command_table, arg_table, name,
241+
event_class):
242+
super(ServiceHelpCommand, self).__init__(session, obj, command_table,
243+
arg_table)
244+
self._name = name
245+
self._event_class = event_class
246+
240247
@property
241248
def event_class(self):
242-
return 'Service'
249+
return self._event_class
243250

244251
@property
245252
def name(self):
246-
return self.obj.endpoint_prefix
253+
return self._name
247254

248255

249256
class OperationHelpCommand(HelpCommand):
@@ -263,7 +270,6 @@ def __init__(self, session, service, operation, arg_table, name,
263270
self._name = name
264271
self._event_class = event_class
265272

266-
267273
@property
268274
def event_class(self):
269275
return self._event_class
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
from tests import unittest
14+
from tests import BaseAWSHelpOutputTest
15+
16+
import mock
17+
18+
from awscli.customizations import utils
19+
20+
21+
class TestCommandTableRenames(BaseAWSHelpOutputTest):
22+
23+
def test_rename_command_table(self):
24+
handler = lambda command_table, **kwargs: utils.rename_command(
25+
command_table, 'ec2', 'fooec2')
26+
# Verify that we can rename a top level command.
27+
self.session.register('building-command-table.main', handler)
28+
self.driver.main(['fooec2', 'help'])
29+
self.assert_contains('fooec2')
30+
31+
# We can also see subcommands help as well.
32+
self.driver.main(['fooec2', 'run-instances', 'help'])
33+
self.assert_contains('run-instances')

0 commit comments

Comments
 (0)