start work on completion
This commit is contained in:
parent
22b84a2fea
commit
0009471f67
3 changed files with 31 additions and 0 deletions
|
@ -207,6 +207,12 @@ def make_parsers():
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Show bash completion script and exit',
|
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(
|
global_group.add_argument(
|
||||||
'--version',
|
'--version',
|
||||||
dest='version',
|
dest='version',
|
||||||
|
|
|
@ -715,6 +715,9 @@ def main(): # pragma: no cover
|
||||||
if global_arguments.bash_completion:
|
if global_arguments.bash_completion:
|
||||||
print(borgmatic.commands.completion.bash_completion())
|
print(borgmatic.commands.completion.bash_completion())
|
||||||
sys.exit(0)
|
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))
|
config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
|
||||||
configs, parse_logs = load_configurations(
|
configs, parse_logs = load_configurations(
|
||||||
|
|
|
@ -55,3 +55,25 @@ def bash_completion():
|
||||||
'\ncomplete -o bashdefault -o default -F complete_borgmatic borgmatic',
|
'\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',
|
||||||
|
))
|
||||||
|
|
Loading…
Reference in a new issue