Repository: python-cmd2/cmd2

Issue:
alias command broken in some circumstances
The ``alias`` command is currently broken on the *master* branch.

A good way to reproduce one case in which it is broken is to use the [alias_startup.py](https://github.com/python-cmd2/cmd2/blob/master/examples/alias_startup.py) example and attempt to run the **pwd** alias as defined in the [.cmd2rc](https://github.com/python-cmd2/cmd2/blob/master/examples/.cmd2rc) startup script.

I believe that the changes in the works on the *macro* branch will fix the current problem.

Comments:

Patch:
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 91b84f0d..c64966a1 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2160,7 +2160,7 @@ class Cmd(cmd.Cmd):
     def do_alias(self, statement: Statement) -> None:
         """Define or display aliases
 
-Usage:  Usage: alias [name] | [<name> <value>]
+    Usage: alias [name] | [<name> <value>]
     Where:
         name - name of the alias being looked up, added, or replaced
         value - what the alias will be resolved to (if adding or replacing)
@@ -2188,7 +2188,8 @@ Usage:  Usage: alias [name] | [<name> <value>]
 
         # If no args were given, then print a list of current aliases
         if not alias_arg_list:
-            for cur_alias in self.aliases:
+            sorted_aliases = utils.alphabetical_sort(list(self.aliases))
+            for cur_alias in sorted_aliases:
                 self.poutput("alias {} {}".format(cur_alias, self.aliases[cur_alias]))
             return
 
@@ -2222,9 +2223,6 @@ Usage:  Usage: alias [name] | [<name> <value>]
                 # Set the alias
                 self.aliases[name] = value
                 self.poutput("Alias {!r} created".format(name))
-
-                # Keep aliases in alphabetically sorted order
-                self.aliases = collections.OrderedDict(sorted(self.aliases.items()))
             else:
                 errmsg = "Aliases can not contain: {}".format(invalidchars)
                 self.perror(errmsg, traceback_war=False)
@@ -2245,7 +2243,7 @@ Usage:  Usage: alias [name] | [<name> <value>]
     def do_unalias(self, arglist: List[str]) -> None:
         """Unsets aliases
 
-Usage:  Usage: unalias [-a] name [name ...]
+    Usage: unalias [-a] name [name ...]
     Where:
         name - name of the alias being unset
 


Test patch:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 17c19f2a..e3992c7b 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1828,7 +1828,22 @@ def test_complete_unalias(base_app):
 
     # Validate that there are now completions
     expected = ['fake', 'fall']
-    assert base_app.complete_unalias(text, line, begidx, endidx) == expected
+    result = base_app.complete_unalias(text, line, begidx, endidx)
+    assert sorted(expected) == sorted(result)
+
+def test_multiple_aliases(base_app):
+    alias1 = 'h1'
+    alias2 = 'h2'
+    run_cmd(base_app, 'alias {} help'.format(alias1))
+    run_cmd(base_app, 'alias {} help -v'.format(alias2))
+    out = run_cmd(base_app, alias1)
+    expected = normalize(BASE_HELP)
+    assert out == expected
+
+    out = run_cmd(base_app, alias2)
+    expected = normalize(BASE_HELP_VERBOSE)
+    assert out == expected
+
 
 def test_ppaged(base_app):
     msg = 'testing...'