Add setup.py and readme
This commit is contained in:
parent
fda4c0681f
commit
b020b9f5b0
59
README.md
59
README.md
@ -1,3 +1,60 @@
|
|||||||
# pargs
|
# pargs
|
||||||
|
|
||||||
Parse command line arguments into a dictionary.
|
Parse command line arguments into a list of args and a dict of kwargs.
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
`pip install pargs`
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
By default, `pargs.parse_args()` uses `sys.argv` as command line arguments.
|
||||||
|
It can be used in the following way.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from pargs import parse_args
|
||||||
|
|
||||||
|
|
||||||
|
args, kwargs = parse_args()
|
||||||
|
```
|
||||||
|
|
||||||
|
The arguments to be parsed can also be specified manually:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from pargs import parse_args
|
||||||
|
|
||||||
|
|
||||||
|
args, kwargs = parse_args(argv=['pargs.py', '--name=Pargs'])
|
||||||
|
```
|
||||||
|
|
||||||
|
# Specification
|
||||||
|
|
||||||
|
`parse_args` parses arguments in the following way:
|
||||||
|
|
||||||
|
Assume the following command line arguments (`sys.argv`):
|
||||||
|
|
||||||
|
```python
|
||||||
|
['/pargs/pargs.py', 'command', 'positional', '--flag', '--optional=value', 'test', '--output-file', 'filename', '-flg', 'name', 'name2']
|
||||||
|
```
|
||||||
|
|
||||||
|
By calling `args, kwargs = parse_args()`, this would return the following list and dict:
|
||||||
|
|
||||||
|
```python
|
||||||
|
args = ['/pargs/pargs.py', 'command', 'positional'],
|
||||||
|
kwargs = {
|
||||||
|
'flag': True,
|
||||||
|
'optional': ['value', 'test'],
|
||||||
|
'output_file': ['filename'],
|
||||||
|
'f': True,
|
||||||
|
'l': True,
|
||||||
|
'g': ['name', 'name2'],
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Basic behaviour
|
||||||
|
|
||||||
|
- All arguments before the first option (starting with a hyphen) are considered positional arguments (`args`)
|
||||||
|
- All other arguments are considered optional keyword arguments (`kwargs`)
|
||||||
|
- Optional arguments without leading hyphens are considered as values to preceding keyword arguments and saved as list
|
||||||
|
- Flags are recorded with the value `True` in the dict
|
||||||
|
- The leading up to two hyphens are stripped from options, all other hyphens are converted into underscores (`---test-this-` would become `_test_this_`)
|
||||||
|
|||||||
18
setup.py
Normal file
18
setup.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
with open('README.md') as f:
|
||||||
|
long_description = f.read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='pargs',
|
||||||
|
version='0.1.0',
|
||||||
|
description='Parse command line arguments into a list of args and a dict of kwargs.',
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
extras_require={
|
||||||
|
'dev':[
|
||||||
|
'pytest',
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
Loading…
x
Reference in New Issue
Block a user