This commit is contained in:
Patrick Elmer 2022-08-30 16:06:08 +09:00
parent 5717f466f3
commit 83b9e1c497
4 changed files with 12 additions and 12 deletions

View File

@ -1,20 +1,20 @@
# pargs
# pargv
Parse command line arguments into a list of args and a dict of kwargs.
# Installation
```python
pip install pargs
pip install pargv
```
# Usage
By default, `pargs.parse_args()` uses `sys.argv` as command line arguments.
By default, `pargv.parse_args()` uses `sys.argv` as command line arguments.
It can be used in the following way.
```python
from pargs import parse_args
from pargv import parse_args
args, kwargs = parse_args()
```
@ -22,19 +22,19 @@ args, kwargs = parse_args()
The arguments to be parsed can also be specified manually:
```python
from pargs import parse_args
from pargv import parse_args
args, kwargs = parse_args(argv=['pargs.py', '--name=Pargs'])
args, kwargs = parse_args(argv=['pargv.py', '--name=pargv'])
```
# Specification
`parse_args` parses arguments in the following way, assuming the following command line arguments (`sys.argv`): `['/pargs/pargs.py', 'command', 'positional', '--flag', '--optional=value', 'test', '--output-file', 'filename', '-flg', 'name', 'name2']`
`parse_args` parses arguments in the following way, assuming the following command line arguments (`sys.argv`): `['/pargv/pargv.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']
args = ['/pargv/pargv.py', 'command', 'positional']
kwargs = {
'flag': True,
'optional': ['value', 'test'],

View File

View File

@ -5,7 +5,7 @@ with open('README.md') as f:
long_description = f.read()
setup(
name='pargs',
name='pargv',
version='0.1.0',
description='Parse command line arguments into a list of args and a dict of kwargs.',
long_description=long_description,

View File

@ -1,7 +1,7 @@
import sys
import pytest
from unittest import mock
from pargs import parse_args
from pargv import parse_args
def test_no_argv():
@ -75,8 +75,8 @@ def test_unintended_hyphen():
@pytest.mark.parametrize('argv, args, kwargs', ((
['/pargs/pargs.py', 'command', 'positional', '--flag', '--optional=value', 'test', '--output-file', 'filename', '-flg', 'name', 'name2'],
['/pargs/pargs.py', 'command', 'positional'],
['/pargv/pargv.py', 'command', 'positional', '--flag', '--optional=value', 'test', '--output-file', 'filename', '-flg', 'name', 'name2'],
['/pargv/pargv.py', 'command', 'positional'],
{
'flag': True,
'optional': ['value', 'test'],