A simple argument parser
Project description
qargs (quick arguments)
qargs
is an argument parser.
qargs
is fast and easy to use. It is great for rapid prototyping and CLI
utilities that need to minimize startup time.
qargs
uses POSIX style argument syntax (mostly). It was implemented according
to the syntax described by the The Open Group Base Specifications (Chapter 12:
Utility conventions). The standard can be read
here.
It intentionally deviates from the standard by not implementing
12.1, 2a and 2b and 12.2, guideline 9.
Why write another argument parser?
Simply put, I don't like how other parsers work. I believe that they are
needlessly difficult to use and most require too much boilerplate code.
Because of this, I frequently found myself writing one-off parsers to meet my
needs. I decided that instead of constantly reinventing the wheel, I needed
more permanent solution; hence qargs
.
Installation
qargs
can be installed with pip: pip install qargs
Example Usage
qargs
provides a single function, parse_args
.
Called without any arguments, parse_args
will do a few handy things for you:
- gather all arguments in the .operands attribute
- gather all files in the .files attribute
- gather all directories in the .directories attribute
- determine whether to read stdin with the .stdin attribute
import qargs
args = qargs.parse_args()
for f in args.files:
# do a thing to each file
parse_args
can be called with a specification to tell it what flags to look for.
import qargs
spec = [
['c', 'color'],
['v', 'verbose'],
]
args = qargs.parse_args(spec)
if args.color:
# be colorful
if args.verbose:
# be verbose
You can provide another value in the spec to capture arguments. If the value evaluates to a bool, the argument is blindly captured. If the value is callable, that callable is used to validate the argument.
import os
import qargs
def validate_config_file(f):
return os.path.isfile(f) and f.endswith('.conf')
spec = [
['c', 'config-file', validate_config_file],
]
args = qargs.parse_args(spec)
with open(args.config_file, 'r') as cf
# read config file
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for quick_arguments-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f91aeb386dd0143d2cd318e07a5cfc1d790ef478f3dd729af52f83f0ebc78fd9 |
|
MD5 | 48cc9bd5e7b89eed7f7ea4f2ce3eae44 |
|
BLAKE2b-256 | 56e0de85786b77136048db3b546bcedbad52c159a5d5ff15073922ceed4bb856 |