Generate options from function.
Project description
Call function directly in cmd line
Features
- Allow user call functions directly in command line.
- Generate help tips automatically.
- Add default called functions if not function was specific.
Notice
- It's better to add argument type for each autocall functions.
- Function with @optfunc_default has @optfunc implicitly.
- Arguments of function with @optfunc_default should be optional or no argument.
- Not support two type of variadic arguments.
ChangeLog
0.1.2 (2023-05-06)
- Add support for default called functions.
- Fix README.md.
- Add ChangeLog in README.md.
Code example
from optfunc2 import *
@optfunc
def arg_test_positional_only(pos_only0, pos_only1: int, pos_only2 = 5, pos_only3: int = 6):
"""summary for the function
Args:
pos_only0 (_type_): This is the first positional-only argument.
pos_only1 (int): This is the second positional-only argument.
pos_only2 (int, optional): This is the third positional-only argument. Defaults to 5.
pos_only3 (int, optional): This is the fourth positional-only argument. Defaults to 6.
"""
" Argument test for positional-only arguments. "
print(f'pos_only0: {pos_only0}, pos_only1: {pos_only1}, pos_only2: {pos_only2}, pos_only3: {pos_only3}')
pass
@optfunc
def arg_test_positional_or_keyword(pos_or_kw, pos_or_kw1: int, pos_or_kw2 = 3, pos_or_kw3: int = 4):
" Argument test for positional-or-keyword arguments. "
print(f'pos_or_kw: {pos_or_kw}, pos_or_kw1: {pos_or_kw1}, pos_or_kw2: {pos_or_kw2}, pos_or_kw3: {pos_or_kw3}')
pass
@optfunc
def arg_test_kw_only(*, kw_only0, kw_only1: int, kw_only2 = 9, kw_only3: int = 10):
" Argument test for keyword-only arguments. "
print(f'kw_only0: {kw_only0}, kw_only1: {kw_only1}, kw_only2: {kw_only2}, kw_only3: {kw_only3}')
pass
if __name__ == '__main__':
optfunc_start(globals=globals(), has_abbrev=False, header_doc='This is a test file for the module "autocall".')
Run the code
~/:$ python3 test.py -h
Usage: test.py [command] [<args>|--help]
This is a test file for the module "autocall".
commands:
arg_test_positional_only summary for the function
arg_test_positional_or_keyword Argument test for positional-or-keyword arguments.
arg_test_kw_only Argument test for keyword-only arguments.
~/:$ python3 test.py arg_test_positional_only -h
Usage: test.py arg_test_positional_only [OPTIONS]
summary for the function
Arguments:
+-------------+------+---------+-------------------------------------------------------------+
| Opt | Type | Default | Desc |
+-------------+------+---------+-------------------------------------------------------------+
| --pos_only0 | any | | This is the first positional-only argument. |
| --pos_only1 | int | | This is the second positional-only argument. |
| --pos_only2 | any | 5 | This is the third positional-only argument. Defaults to 5. |
| --pos_only3 | int | 6 | This is the fourth positional-only argument. Defaults to 6. |
+-------------+------+---------+-------------------------------------------------------------+
~/:$ python3 test.py arg_test_positional_only --pos_only0 "good day" --pos_only1 2
pos_only0: good day, pos_only1: 2, pos_only2: 5, pos_only3: 6
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
optfunc2-0.2.0.tar.gz
(6.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optfunc2-0.2.0.tar.gz.
File metadata
- Download URL: optfunc2-0.2.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0836997aea173a1e508368cb61fac2eadc44560e3152c19cd5fb9d2b85c68d31
|
|
| MD5 |
7485060c5f2dec857c638db63d7bdb61
|
|
| BLAKE2b-256 |
2d4f8f1ec65011cb6618f2053dbe0bbe7addedca12ee37975b016b74a1ba0363
|
File details
Details for the file optfunc2-0.2.0-py3-none-any.whl.
File metadata
- Download URL: optfunc2-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bfa7efb9b93fff7f04780511a122442b2b4c1bdf29427b02709015dd86ef976
|
|
| MD5 |
70561afb7639ef3e272b76b85cdad502
|
|
| BLAKE2b-256 |
d7c081ce6913efc33f9f7ecf89ba16d977aa199b1b0e7074bff28ac37ae7a3a7
|