Skip to content

Commit

Permalink
Move command aliasing to different function
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Apr 11, 2017
1 parent bd36d51 commit 10af063
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
7 changes: 3 additions & 4 deletions awscli/customizations/mturk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.customizations.utils import alias_command
from awscli.customizations.utils import make_hidden_command_alias


def register_alias_mturk_command(event_emitter):
Expand All @@ -21,9 +21,8 @@ def register_alias_mturk_command(event_emitter):


def alias_mturk_command(command_table, **kwargs):
alias_command(
make_hidden_command_alias(
command_table,
existing_name='list-hits-for-qualification-type',
new_name='list-hi-ts-for-qualification-type',
hide_current=False
alias_name='list-hi-ts-for-qualification-type',
)
36 changes: 25 additions & 11 deletions awscli/customizations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def rename_command(command_table, existing_name, new_name):
del command_table[existing_name]


def alias_command(command_table, existing_name, new_name, hide_current=True):
def alias_command(command_table, existing_name, new_name):
"""Moves an argument to a new name, keeping the old as a hidden alias.
:type command_table: dict
Expand All @@ -77,19 +77,33 @@ def alias_command(command_table, existing_name, new_name, hide_current=True):
:type new_name: str
:param new_name: The new name for the command.
:type hide_current: bool
:param hide_current: Whether to hide the current command name or the new
command name. If True, the current name is hidden. If False, the new
name is hidden.
"""
current = command_table[existing_name]
new = _copy_argument(command_table, existing_name, new_name)
_copy_argument(command_table, existing_name, new_name)
current._UNDOCUMENTED = True


def make_hidden_command_alias(command_table, existing_name, alias_name):
"""Create a hidden alias for an exiting command.
This will copy an existing command object in a command table and add a new
entry to the command table with a different name. The new command will
be undocumented.
This is needed if you want to change an existing command, but you still
need the old name to work for backwards compatibility reasons.
:type command_table: dict
:param command_table: The full command table for the CLI or a service.
:type existing_name: str
:param existing_name: The current name of the command.
if hide_current:
current._UNDOCUMENTED = True
else:
new._UNDOCUMENTED = True
:type alias_name: str
:param alias_name: The new name for the command.
"""
new = _copy_argument(command_table, existing_name, alias_name)
new._UNDOCUMENTED = True


def validate_mutually_exclusive_handler(*groups):
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/customizations/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ def test_alias_command_table(self):
def handler(command_table, **kwargs):
utils.alias_command(command_table, old_name, new_name)

self._assert_commands_exist(old_name, new_name, handler)
self._assert_command_exists(old_name, handler)
self._assert_command_exists(new_name, handler)

# Verify that the new name is documented
self.driver.main(['help'])
self.assert_contains(new_name)
self.assert_not_contains(old_name)

def test_hide_new_command_name(self):
def test_make_hidden_alias(self):
old_name = 'ec2'
new_name = 'nopossiblewaythisisalreadythere'

def handler(command_table, **kwargs):
utils.alias_command(command_table, old_name, new_name, False)
utils.make_hidden_command_alias(command_table, old_name, new_name)

self._assert_command_exists(old_name, handler)
self._assert_command_exists(new_name, handler)
Expand Down

0 comments on commit 10af063

Please sign in to comment.