-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate bash autocompletion setup
This commit replaces the bash autocomplete script with a command to generate a bash autocomplete script. This is because the setuptools `data_files` option/section is deprecated, and there's really no good way to install this file with setuptools.
- Loading branch information
Showing
3 changed files
with
101 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
""" Get autocomplete script """ | ||
from __future__ import ( | ||
absolute_import, | ||
division, | ||
print_function, | ||
unicode_literals, | ||
) | ||
|
||
import argparse | ||
import logging | ||
import shlex | ||
# import textwrap | ||
|
||
from . import methods | ||
from . import cli_utils | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
OPTIONS = ( | ||
"--list-all", | ||
"--list-methods", | ||
"--list-params", | ||
"--no-verify", | ||
"--show-docstring", | ||
"--show-params", | ||
"--version", | ||
"-h", "--help", | ||
"-p", "--param", | ||
"-s", "--show-plaintext", | ||
"-v", "--verbose", | ||
) | ||
|
||
|
||
template = """ | ||
_mkcrypt_autocomplete() | ||
{{ | ||
local curr | ||
local -a methods opts | ||
curr="${{COMP_WORDS[$COMP_CWORD]}}" | ||
methods=( {methods} ) | ||
opts=( {options} ) | ||
COMPREPLY=() | ||
if [[ "$curr" == -* ]]; | ||
then | ||
COMPREPLY=( $(compgen -W "${{opts[*]}}" -- "$curr") ) | ||
elif [ "${{COMP_CWORD}}" -gt 1 ] \\ | ||
&& [ "${{COMP_WORDS[$COMP_CWORD-1]}}" == "-p" ]; | ||
then | ||
# TODO: Implement fetching known/valid settings from mkcrypt | ||
COMPREPLY=() | ||
else | ||
COMPREPLY=( $(compgen -W "${{methods[*]}}" -- "$curr") ) | ||
fi | ||
}} | ||
complete -F _mkcrypt_autocomplete passlib-mkpasswd | ||
""" | ||
|
||
|
||
def format_text_list(items): | ||
return " ".join(shlex.quote(item) for item in items) | ||
|
||
|
||
def format_autocomplete_script(methods): | ||
return template.format( | ||
options=format_text_list(OPTIONS), | ||
methods=format_text_list(methods), | ||
) | ||
|
||
|
||
def main(inargs=None): | ||
parser = argparse.ArgumentParser( | ||
description="Make autocomplete bash script for passlib", | ||
) | ||
|
||
cli_utils.add_verbosity_mutex(parser) | ||
cli_utils.add_version_arg(parser) | ||
args = parser.parse_args(inargs) | ||
|
||
cli_utils.setup_logging(args.verbosity) | ||
|
||
supported_methods = [m for m in methods.values() if m.supported] | ||
method_list = [m.name for m in supported_methods] | ||
|
||
# m = methods[args.show_params] | ||
# for param in sorted(m.settings): | ||
# print(param) | ||
|
||
script = format_autocomplete_script(method_list) | ||
print(script) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |