Commandopt-0.2.0
توضیحات
Turn a dict of arguments into cli commands, ideal companion of docopt.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | Commandopt-0.2.0 |
| نام | Commandopt |
| نسخه کتابخانه | 0.2.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | notmarrco |
| ایمیل نویسنده | marc@maj44.com |
| آدرس صفحه اصلی | https://github.com/jaegerbobomb/commandopt |
| آدرس اینترنتی | https://pypi.org/project/Commandopt/ |
| مجوز | - |
# commandopt
Turn a dict of arguments into cli commands, ideal companion of docopt.
## Why ?
Using the `commandopt.commandopt` decorator, you are able to declare commands to be
executed depending on the input arguments of your app (required or optional).
It reduces the boilerplate code in your `main()`.
## Declaration
```py
def commandopt(mandopts: List, opts: List = None):
# ...
```
### Call
```py
@commandopt(mandatory_arguments, optional_arguments)
def xxxx(*args, **kwargs):
```
## Example usage
```py
#myapp/myapp.py
"""Naval Fate.
Usage:
naval_fate.py ship new <name>...
naval_fate.py new-ship [<name>]
naval_fate.py --version
Options:
--version Show version.
"""
from commandopt import Command
from docopt import docopt
import myapp.commands.ship
if __name__ == '__main__':
arguments = docopt(__doc__, version='Naval Fate 2.0')
run = Command(arguments) # get the registered function
run(arguments) # execute the function
# or
# run = Command(arguments, call=True)
```
```py
#myapp/commands/ship.py
from commandopt import commandopt
class ShipCommand:
@commandopt(["ship", "new", "<name>"])
@commandopt(["new-ship"], ["<name>"])
def new(arguments):
"""You can stack the decorator if you want."""
name = arguments["<name>"] or "case when name is empty"
# ... your code here
```
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.2 | Python |
نحوه نصب
نصب پکیج whl Commandopt-0.2.0:
pip install Commandopt-0.2.0.whl
نصب پکیج tar.gz Commandopt-0.2.0:
pip install Commandopt-0.2.0.tar.gz