use fstring to produce completion lines

This commit is contained in:
Isaac 2023-05-04 13:33:21 -07:00
parent 062453af51
commit f04036e4a7
No known key found for this signature in database
GPG key ID: E69FB5A841448A48

View file

@ -108,25 +108,17 @@ def fish_completion():
) )
+ ('\n# subparser completions',) + ('\n# subparser completions',)
+ tuple( + tuple(
'''complete -c borgmatic -a '%s' -d %s -f -n "not __fish_seen_subcommand_from %s"''' f'''complete -c borgmatic -a '{action_name}' -d {shlex.quote(subparser.description)} -f -n "not __fish_seen_subcommand_from {all_subparsers}"'''
% (action_name, shlex.quote(subparser.description), all_subparsers)
for action_name, subparser in subparsers.choices.items() for action_name, subparser in subparsers.choices.items()
) )
+ ('\n# global flags',) + ('\n# global flags',)
+ tuple( + tuple(
'''complete -c borgmatic -a '%s' -d %s %s''' f'''complete -c borgmatic -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)} {build_fish_flags(action)}'''
% (' '.join(action.option_strings), shlex.quote(action.help), build_fish_flags(action))
for action in top_level_parser._actions for action in top_level_parser._actions
) )
+ ('\n# subparser flags',) + ('\n# subparser flags',)
+ tuple( + tuple(
'''complete -c borgmatic -a '%s' -d %s -n "__fish_seen_subcommand_from %s" %s''' f'''complete -c borgmatic -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)} -n "__fish_seen_subcommand_from {action_name}" {build_fish_flags(action)}'''
% (
' '.join(action.option_strings),
shlex.quote(action.help),
action_name,
build_fish_flags(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
) )