本文整理汇总了Python中thefuck.utils.replace_argument函数的典型用法代码示例。如果您正苦于以下问题:Python replace_argument函数的具体用法?Python replace_argument怎么用?Python replace_argument使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace_argument函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_new_command
def get_new_command(command):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r"did not match any file\(s\) known to git.", command.output)[0]
closest_branch = utils.get_closest(missing_file, get_branches(),
fallback_to_first=False)
if closest_branch:
return replace_argument(command.script, missing_file, closest_branch)
elif command.script_parts[1] == 'checkout':
return replace_argument(command.script, 'checkout', 'checkout -b')
else:
return shell.and_('git branch {}', '{}').format(
missing_file, command.script)
示例2: get_new_command
def get_new_command(command):
destination = _get_destination(command)
paths = _get_all_absolute_paths_from_history(command)
return [replace_argument(command.script, destination, path)
for path in paths if path.endswith(destination)
and Path(path).expanduser().exists()]
示例3: get_new_command
def get_new_command(command):
for idx, arg in enumerate(command.script_parts[1:]):
# allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args
# for example 'adb -s 111 logcat' or 'adb -e logcat'
if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H', '-P', '-L'):
adb_cmd = get_closest(arg, _ADB_COMMANDS)
return replace_argument(command.script, arg, adb_cmd)
示例4: get_new_command
def get_new_command(command):
misspelled_task = regex.findall(command.output)[0]
if misspelled_task in npm_commands:
yarn_command = npm_commands[misspelled_task]
return replace_argument(command.script, misspelled_task, yarn_command)
else:
tasks = _get_all_tasks()
return replace_command(command, misspelled_task, tasks)
示例5: get_new_command
def get_new_command(command, settings):
stash_cmd = command.script.split()[2]
fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False)
if fixed is not None:
return replace_argument(command.script, stash_cmd, fixed)
else:
cmd = command.script.split()
cmd.insert(2, 'save')
return ' '.join(cmd)
示例6: get_new_command
def get_new_command(command, settings):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r"did not match any file\(s\) known to git.", command.stderr)[0]
closest_branch = utils.get_closest(missing_file, get_branches(),
fallback_to_first=False)
if closest_branch:
return replace_argument(command.script, missing_file, closest_branch)
else:
return shells.and_('git branch {}', '{}').format(
missing_file, command.script)
示例7: get_new_command
def get_new_command(command):
# If --set-upstream or -u are passed, remove it and its argument. This is
# because the remaining arguments are concatenated onto the command suggested
# by git, which includes --set-upstream and its argument
command_parts = command.script_parts[:]
upstream_option_index = _get_upstream_option_index(command_parts)
if upstream_option_index is not None:
command_parts.pop(upstream_option_index)
# In case of `git push -u` we don't have next argument:
if len(command_parts) > upstream_option_index:
command_parts.pop(upstream_option_index)
push_upstream = command.stderr.split('\n')[-3].strip().partition('git ')[2]
return replace_argument(" ".join(command_parts), 'push', push_upstream)
示例8: get_new_command
def get_new_command(command):
# If --set-upstream or -u are passed, remove it and its argument. This is
# because the remaining arguments are concatenated onto the command suggested
# by git, which includes --set-upstream and its argument
command_parts = command.script_parts[:]
upstream_option_index = _get_upstream_option_index(command_parts)
if upstream_option_index is not None:
command_parts.pop(upstream_option_index)
# In case of `git push -u` we don't have next argument:
if len(command_parts) > upstream_option_index:
command_parts.pop(upstream_option_index)
arguments = re.findall(r'git push (.*)', command.output)[0].strip()
return replace_argument(" ".join(command_parts), 'push',
'push {}'.format(arguments))
示例9: get_new_command
def get_new_command(command):
# If --set-upstream or -u are passed, remove it and its argument. This is
# because the remaining arguments are concatenated onto the command suggested
# by git, which includes --set-upstream and its argument
command_parts = command.script_parts[:]
upstream_option_index = _get_upstream_option_index(command_parts)
if upstream_option_index is not None:
command_parts.pop(upstream_option_index)
# In case of `git push -u` we don't have next argument:
if len(command_parts) > upstream_option_index:
command_parts.pop(upstream_option_index)
else:
# the only non-qualified permitted options are the repository and refspec; git's
# suggestion include them, so they won't be lost, but would be duplicated otherwise.
push_idx = command_parts.index('push') + 1
while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
command_parts.pop(len(command_parts) - 1)
arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
return replace_argument(" ".join(command_parts), 'push',
'push {}'.format(arguments))
示例10: get_new_command
def get_new_command(command):
to = command.stderr.split('`')[1]
return replace_argument(command.script, to[1:], to)
示例11: get_new_command
def get_new_command(command, settings):
return replace_argument(command.script, 'pull', 'clone')
示例12: get_new_command
def get_new_command(command):
not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)',
command.stderr)[0]
exist_formula = _get_similar_formula(not_exist_formula)
return replace_argument(command.script, not_exist_formula, exist_formula)
示例13: get_new_command
def get_new_command(command, settings):
return shells.and_(replace_argument(command.script, "push", "pull"), command.script)
示例14: get_new_command
def get_new_command(command):
return replace_argument(command.script, 'add', 'add --force')
示例15: test_replace_argument
def test_replace_argument(args, result):
assert replace_argument(*args) == result