start work on completion

This commit is contained in:
Isaac 2023-04-27 18:46:13 -07:00
parent 22b84a2fea
commit 0009471f67
No known key found for this signature in database
GPG Key ID: E69FB5A841448A48
3 changed files with 31 additions and 0 deletions

View File

@ -207,6 +207,12 @@ def make_parsers():
action='store_true',
help='Show bash completion script and exit',
)
global_group.add_argument(
'--fish-completion',
default=False,
action='store_true',
help='Show fish completion script and exit',
)
global_group.add_argument(
'--version',
dest='version',

View File

@ -715,6 +715,9 @@ def main(): # pragma: no cover
if global_arguments.bash_completion:
print(borgmatic.commands.completion.bash_completion())
sys.exit(0)
if global_arguments.fish_completion:
print(borgmatic.commands.completion.fish_completion())
sys.exit(0)
config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
configs, parse_logs = load_configurations(

View File

@ -55,3 +55,25 @@ def bash_completion():
'\ncomplete -o bashdefault -o default -F complete_borgmatic borgmatic',
)
)
def fish_completion():
'''
Return a fish completion script for the borgmatic command. Produce this by introspecting
borgmatic's command-line argument parsers.
'''
top_level_parser, subparsers = arguments.make_parsers()
global_flags = parser_flags(top_level_parser)
actions = ' '.join(subparsers.choices.keys())
# Avert your eyes.
return '\n'.join(
(
'function __borgmatic_check_version',
' set this_script (cat "$BASH_SOURCE" 2> /dev/null)',
' set installed_script (borgmatic --bash-completion 2> /dev/null)',
' if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ]',
f' echo "{UPGRADE_MESSAGE}"',
' end',
'end',
'function __borgmatic_complete',
))