From 6dc64d3781cc13c3f4cb902656210c3d07e93f9e Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 7 Apr 2015 17:19:35 +0000 Subject: [PATCH] Automatically upgrade '_' to '-' when finding the right command. This doesn't change the automatic command finder, so it really only helps increase match hit rate in case of low confidence level delta between the 2 top hits. For example, given commands 'set-commit' and 'dcommit', a user typing 'set_commit' would hit: - 'set-commit': 90% - 'dcommit': 70.5% Since subcommand.py uses a 30% minimum confidence level between the two top hit to automatically select a command, it will err on the side of safety and will abort instead of selecting 'set-commit'. This change fixes this specific case but won't trigger on partial matches, e.g. 'set_commi' for 'set-commit'. R=stip@chromium.org BUG= Review URL: https://codereview.chromium.org/1066923003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294700 0039d316-1c4b-4281-b951-d872f2087c98 --- subcommand.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subcommand.py b/subcommand.py index 0201c90aa3..a9ebae098d 100644 --- a/subcommand.py +++ b/subcommand.py @@ -128,8 +128,9 @@ class CommandDispatcher(object): and/or incomplete names. """ commands = self.enumerate_commands() - if name_asked in commands: - return commands[name_asked] + name_to_dash = name_asked.replace('_', '-') + if name_to_dash in commands: + return commands[name_to_dash] # An exact match was not found. Try to be smart and look if there's # something similar.