ArgChooser
ArgChooser is Python module which allows for fast and easy creation of function chooser.
- Gives end-user an option to choose which functions to execute by cmdline args or cmdline menu
- Just add flag names and functions
- Execute and watch magic!
Table of Contents
Documentation
Installation
Simply use pip to install the ArgChooser package
pip install argchoose
Quick Start
Using ArgChooser is as simple as possible. Simple three steps:
- Create object of ArgChooser
- Bind methods with flags using add_argument
- Execute ArgChooser!
from argchoose import ArgChooser
def foo():
print('bar')
ac = ArgChooser()
ac.add_argument('-f', '--foo', method=foo)
ac.execute()
Now You are able to run your program from cmdline like that to execute method:
python example.py -f
Or without flags to see this:
Examples
Adding arguments
add_argument - allows to bind flag (or flags) with chosen method.
It is possible to also specify category and help prompt.
Takes *flags: str, method: Callable [, help: str, category: str]
Returns nothing.
Example is based on This.
Categories allows to make menu clearer.
As You can see, help also makes it more descriptive, but also could be printed using -h flag like cmdline tools usually do!
python default_usage.py -h
To execute chosen methods, end-user has to choose, if they want to use it straight from cmdline or menu:
Changing default ArgChooser parameters
ArgChooser could be initialized without any parameters, but gives possibility to change a few little things as shown Here.
Takes [category_style: str, default_category_name: str, style: Dict[Token, str], validation_func: Callable(List) -> bool, validation_error: str].
category_style is string on which is used format method with category name.
{} must be included in string.
Default is == {} ==.
default_category_name is string which will be used as category name for every uncategorized methods.
Default is Other.
style is dictionary made from Tokens and strings which represents hex colors with textformatting keywords (like bold).
validation_func is function used for validating answers at the end of parsing (for example for checking if amount of answers is bigger than two).
This function must take one argument which is List and must return bool value.
Default functions checks if any answer is chosen.
validation_error is string which will be printed if validation_func returned False.
Default is You must choose at least one module..
When validation_func return False, validation_error is printed like that:
This is going to be changed to this, after releasing new version of PyInquirer with fixed validation parameter:
License
Copyright (c) 2020 Paweł Kusiński
Distributed under the MIT License. See LICENSE for more information.
Metadata
Release files for argchoose 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| argchoose-0.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / argchoose-0.1-py3-none-any.whl
| Download URL | argchoose-0.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee55656542d54bd5deb57f93712efd2d7dee6456db6ce8871b0bc3ccbfa1e9ab
|
|
BLAKE2b-256 checksum How to use checksums |
167e2c139990ab216d69e4245e9c4b8d1cc22b103e2165ca36a5cea01ecbd57b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|