rename function

This commit is contained in:
Isaac 2023-05-04 21:14:48 -07:00
parent bbc3e9d717
commit 193731a017
No known key found for this signature in database
GPG key ID: E69FB5A841448A48

View file

@ -66,20 +66,20 @@ def bash_completion():
) )
) )
file_metavars = ( file_metavars = (
'FILENAME', 'FILENAME',
'PATH', 'PATH',
) )
file_destinations = ( file_destinations = 'config_paths'
'config_paths'
)
def conditionally_emit_file_completion(action: Action): def conditionally_emit_arg_completion(action: Action):
''' '''
Given an argparse.Action instance, return a completion invocation that forces file completion Given an argparse.Action instance, return a completion invocation
if the action takes a file argument and was the last action on the command line. that forces file completion or options completion, if the action
takes such an argument and was the last action on the command line.
Otherwise, return an empty string. Otherwise, return an empty string.
''' '''
@ -91,7 +91,7 @@ def conditionally_emit_file_completion(action: Action):
f''' f'''
complete -c borgmatic -a '{args}' -Fr -n "__borgmatic_last_arg {args}"''' complete -c borgmatic -a '{args}' -Fr -n "__borgmatic_last_arg {args}"'''
) )
if action.choices: if action.choices:
return dedent( return dedent(
f''' f'''
@ -157,13 +157,13 @@ def fish_completion():
) )
+ ('\n# global flags',) + ('\n# global flags',)
+ tuple( + tuple(
f'''complete -c borgmatic -f -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)}{conditionally_emit_file_completion(action)}''' f'''complete -c borgmatic -f -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)}{conditionally_emit_arg_completion(action)}'''
for action in top_level_parser._actions for action in top_level_parser._actions
if len(action.option_strings) > 0 if len(action.option_strings) > 0
) )
+ ('\n# subparser flags',) + ('\n# subparser flags',)
+ tuple( + tuple(
f'''complete -c borgmatic -f -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)} -n "__fish_seen_subcommand_from {action_name}"{conditionally_emit_file_completion(action)}''' f'''complete -c borgmatic -f -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)} -n "__fish_seen_subcommand_from {action_name}"{conditionally_emit_arg_completion(action)}'''
for action_name, subparser in subparsers.choices.items() for action_name, subparser in subparsers.choices.items()
for action in subparser._actions for action in subparser._actions
) )