A tool to create a command-line interface for your app using python
Project description
betterargs
A tool to create a command-line interface for your app using python
Installation
pip install betterargs
- Requirements
- python3.10
- pip3
Releases
Packaging and releases are handled in the packaging branch. MAIN BRANCH IS RESERVED FOR MAINTAINING CODE ONLY!!!
Usage
-
Create a command string in YAML format in a:
- YAML file
- Python dictionary
- Python string
-
Convert the yaml file to command line namespace using appropriate function
-
Using a YAML file
- Create command tree in a yaml file
git:
args:
path:
atype: flag
help: Path of the repo
subparsers:
parsers:
clone:
args:
quiet-clone:
atype: flag
help: Operate quietly. Progress is not reported to the standard error stream.
no-checkout:
help: No checkout of HEAD is performed after the clone is complete
init:
args:
quiet-init:
atype: flag
help: Operate quietly. Progress is not reported to the standard error stream.
- Convert the yaml file to command line namespace using betterargs.format_path_tree function
import betterargs
# Create command line namespace and get arguments
command_tree_PATH = 'command_tree.yaml'
args = betterargs.format_path_tree(command_tree_PATH)
-
Using Python Dictionary in YAML Format
- Create command tree in a python dictionary in YAML format
command_tree_DICT = {
"git": {
"args": {
"path": {
"atype": "flag",
"help": "Path of the repo",
},
},
"subparsers": {
"parsers": {
"clone": {
"args": {
"quiet-clone": {
"atype": "flag",
"help": "Operate quietly. Progress is not reported to the standard error stream.",
},
"no-checkout": {
"help": "No checkout of HEAD is performed after the clone is complete"
},
},
},
"init": {
"args": {
"quiet-init": {
"atype": "flag",
"help": "Operate quietly. Progress is not reported to the standard error stream.",
},
},
},
},
},
},
}
- Convert the dictionary to command line namespace using betterargs.format_dict_tree function
import betterargs
# Create command line namespace and get arguments
args = betterargs.format_dict_tree(command_tree_DICT)
-
Using YAML Format string
- Create command tree in a python string in YAML format
# Define command tree in YAML string format
command_tree_STR = """
git:
args:
path:
atype: flag
help: Path of the repo
subparsers:
parsers:
clone:
args:
quiet-clone:
atype: flag
help: Operate quietly. Progress is not reported to the standard error stream.
no-checkout:
help: No checkout of HEAD is performed after the clone is complete
init:
args:
quiet-init:
atype: flag
help: Operate quietly. Progress is not reported to the standard error stream.
"""
- Convert the dictionary to command line namespace using betterargs.format_str_tree function
import betterargs
# Create command line namespace and get arguments
args = betterargs.format_str_tree(command_tree_STR)
Contribution
You are more than welcome to contribute 😊 It doe
It's simple!!!
-
Fork the repo
-
Clone the repo
git clone https://github.com/danielmuringe/betterargs
-
Make your modifications in the dev
-
Merge into main branch respecting the .gitignore of the main branch. KEEP IT CLEAN !!!
-
Create pull request
-
Wait for confirmation
Tests
- Tests can be found in the testing directory of dev branch
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
betterargs-0.0.2.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for betterargs-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bcc964fcbe151b230d61afb7fb38ace308f991d19f23ffd898ddc3b7ef30144 |
|
MD5 | bc7e80672ce0f808534d947959b5a570 |
|
BLAKE2b-256 | 0074ee0973bd0dc4b67576c1897a113031ffd1e9821fae417dde5c6bfe3c18f8 |