completion-utils-0.0.2
توضیحات
A set of functions intended to make writing shell completion functions lot easier by letting you write them via python.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | completion-utils-0.0.2 |
| نام | completion-utils |
| نسخه کتابخانه | 0.0.2 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Carvell Scott |
| ایمیل نویسنده | carvell.scott@gmail.com |
| آدرس صفحه اصلی | https://github.com/CarvellScott/completion_utils |
| آدرس اینترنتی | https://pypi.org/project/completion-utils/ |
| مجوز | - |
# completion_utils
A lightweight set of functions intended to make writing shell completion functions in python easier. Install with `pip install completion-utils` and import what you need from `completion_utils`. Generally you only need to import `bash_completion_decorator`, and decorate a function with it.
## Usage
Supposing you have some simple completion like this already...
```
#!/usr/bin/env python3
import sys
def foobar():
return ["a", "bunch", "of", "potential", "matches"]
def completion_hook(cmd, curr_word, prev_word):
potential_matches = foobar()
matches = [k for k in potential_matches if k.startswith(curr_word)]
return matches
def main():
results = completion_hook(*sys.argv[1:])
if len(results):
print("\n".join(results))
if __name__ == "__main__":
main()
```
You can then decorate `completion_hook` with `bash_completion_decorator` to have shell completion automatically supply the necessary arguments and use bash_complete to test out the results of potential completions.
```
#!/usr/bin/env python3
import sys
import unittest
from completion_utils import bash_completion_decorator, bash_complete
class CompletionTestCase_up(unittest.TestCase):
def test_all_options_show(self):
expected = "\n".join(sorted(foobar()))
actual = bash_complete("heylook ", __file__)
def test_one_option(self):
expected = "m"
actual = bash_complete("heylook m", __file__)
def foobar():
return ["a", "bunch", "of", "potential", "matches"]
@bash_completion_decorator
def completion_hook(cmd, curr_word, prev_word):
potential_matches = foobar()
matches = [k for k in potential_matches if k.startswith(curr_word)]
return matches
if __name__ == "__main__":
completion_hook()
```
نحوه نصب
نصب پکیج whl completion-utils-0.0.2:
pip install completion-utils-0.0.2.whl
نصب پکیج tar.gz completion-utils-0.0.2:
pip install completion-utils-0.0.2.tar.gz