def get_new_command(command): """ Attempt to rebuild the path string by spellchecking the directories. If it fails (i.e. no directories are a close enough match), then it defaults to the rules of cd_mkdir. Change sensitivity by changing MAX_ALLOWED_DIFF. Default value is 0.6 """ dest = command.script_parts[1].split(os.sep) if dest[-1] == '': dest = dest[:-1] if dest[0] == '': cwd = os.sep dest = dest[1:] elif six.PY2: cwd = os.getcwdu() else: cwd = os.getcwd() for directory in dest: if directory == ".": continue elif directory == "..": cwd = os.path.split(cwd)[0] continue best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF) if best_matches: cwd = os.path.join(cwd, best_matches[0]) else: return cd_mkdir.get_new_command(command) return u'cd "{0}"'.format(cwd)
def get_new_command(command): command_list = [ 'git rebase --continue', 'git rebase --abort', 'git rebase --skip' ] rm_cmd = command.output.split('\n')[-4] command_list.append(rm_cmd.strip()) return get_close_matches(command.script, command_list, 4, 0)
def get_new_command(command): failed_lifecycle = _get_failed_lifecycle(command) available_lifecycles = _getavailable_lifecycles(command) if available_lifecycles and failed_lifecycle: selected_lifecycle = get_close_matches( failed_lifecycle.group(1), available_lifecycles.group(1).split(", ")) return replace_command(command, failed_lifecycle.group(1), selected_lifecycle) else: return []
def get_new_command(command): old_command = command.script_parts[0] # One from history: already_used = get_closest(old_command, _get_used_executables(command), fallback_to_first=False) if already_used: new_cmds = [already_used] else: new_cmds = [] # Other from all executables: new_cmds += [ cmd for cmd in get_close_matches(old_command, get_all_executables()) if cmd not in new_cmds ] return [ ' '.join([new_command] + command.script_parts[1:]) for new_command in new_cmds ]
def match(command): return len(get_close_matches(command.script, get_valid_history_without_current(command)))
def test_call_without_n(self, difflib_mock, settings): get_close_matches('', []) assert difflib_mock.call_args[0][2] == settings.get( 'num_close_matches')
def test_call_with_n(self, difflib_mock): get_close_matches('', [], 1) assert difflib_mock.call_args[0][2] == 1
def match(command): return (not which(command.script_parts[0]) and ('not found' in command.output or 'is not recognized as' in command.output) and bool( get_close_matches(command.script_parts[0], get_all_executables())))