Bug 1335620 - Don't assume "uninstall" means "install" r?gps draft
authorWes Kocher <wkocher@mozilla.com>
Sat, 16 Sep 2017 18:40:56 -0700
changeset 666028 280804a3b38d713cc7c19c10ef33dc6b2269abe9
parent 665648 6be5c7d30d2def62a762ac187252eba626b23a92
child 731951 b8c1768f7ddbf467b637c717045b8d247dc66266
push id80245
push userbmo:wkocher@mozilla.com
push dateSun, 17 Sep 2017 01:41:10 +0000
reviewersgps
bugs1335620
milestone57.0a1
Bug 1335620 - Don't assume "uninstall" means "install" r?gps `mach install` is a command to install the package onto the device. People might assume that `mach uninstall` exists and does the opposite of `mach install`, but it doesn't. When the user runs `mach uninstall`, mach helpfully looks for suggested similar commands, and picks `install` as the best option and immediately proceeds to run it. This patch explicitly prevents mach from looking for suggestions when the entered command is `uninstall`. MozReview-Commit-ID: 4Hpk8G23yTk
python/mach/mach/dispatcher.py
--- a/python/mach/mach/dispatcher.py
+++ b/python/mach/mach/dispatcher.py
@@ -416,17 +416,17 @@ class CommandAction(argparse.Action):
                     if h.cls.__name__ != 'DeprecatedCommands']
         # We first try to look for a valid command that is very similar to the given command.
         suggested_commands = difflib.get_close_matches(command, names, cutoff=0.8)
         # If we find more than one matching command, or no command at all,
         # we give command suggestions instead (with a lower matching threshold).
         # All commands that start with the given command (for instance:
         # 'mochitest-plain', 'mochitest-chrome', etc. for 'mochitest-')
         # are also included.
-        if len(suggested_commands) != 1:
+        if len(suggested_commands) != 1 or command == 'uninstall':
             suggested_commands = set(difflib.get_close_matches(command, names, cutoff=0.5))
             suggested_commands |= {cmd for cmd in names if cmd.startswith(command)}
             raise UnknownCommandError(command, 'run', suggested_commands)
         sys.stderr.write("We're assuming the '%s' command is '%s' and we're "
                          "executing it for you.\n\n" % (command, suggested_commands[0]))
         return suggested_commands[0]