A python library for parsing command line arguments
Project description
BlinkParse
A python library for parsing command line arguments
Installation
pip install blinkparse
Usage
Parser(args=[], commands=[], description='', commandRequired=False, noOperands=False)
- Returns a
blinkparse.Argumentsobject argsis a list ofblinkparse.Argumentobjectscommandsis a list ofblinkparse.Commandobjectsdescriptionis a description to show at the top of the help pagecommandRequiredis whether the program requires a command to be passed innoOperandsis whether the program is allowed to take operandsparse(inputArgs=None)- Returns a
blinkparse.Argumentsobject inputArgsis a list of the arguments to parse. This defaults tosys.argv[1:]
- Returns a
Argument(name, shortName=None, takesValue=False, required=False, description=None)
nameis the argument name used in the long syntax (--myArg,--myArg=myValue)shortNameis the argument name used in the long syntax (-a,-a myValue)takesValueis whether the argument takes a input (see above)requiredmakes the blinkparse raise an error if the argument isn't passed indescriptionis a description to show in the help page
Command(name, args=[], aliases=[])
- Usage
Command('hello', [CommandArgument('person'), CommandArgument('gender', required=False, options=['male', 'female', 'other])], 'h')$ python3 example.py hello jered$ python3 example.py hello joe male
nameis the name of the commandargsis a list ofblinkparse.CommandArgumentobjects that the command takesCommandArgument(name, options=None, required=True)nameis the name of the command argumentoptionsis a list of allowed options for the argument (defaults to everything)requiredmakes blinkparse raise an error if the command argument isn't passed in
aliasesis a list of other names for the command
Full example
from blinkparse import *
args = Parser(
args=[
Argument('save', 's', description='Save the program output'),
],
commands=[
Command('hello', [
CommandArgument('person'),
CommandArgument('gender', required=False, options=['male', 'female', 'other'])
]),
Command('bye', [
CommandArgument('person')
])
],
description='''
hello.py
A simple demo of blinkparse
''',
commandRequired=True
).parse()
if args.command == 'hello':
output = 'Hello ' + args.commandArgs['person']
if 'gender' in args.commandArgs:
output += ', you are ' + args.commandArgs['gender']
else:
output = 'Bye ' + args.commandArgs['person']
if 'save' in args.args:
with open('hello.txt', 'w') as outputFile:
outputFile.write(output)
else:
print(output)
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
blinkparse-0.1.5.tar.gz
(3.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blinkparse-0.1.5.tar.gz.
File metadata
- Download URL: blinkparse-0.1.5.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81cc224c38e452aa61f927baf568610dbaf949089fe9f649151d33d687b6b271
|
|
| MD5 |
9e2c4f4a7541aa5e499cd26aa4f3a31e
|
|
| BLAKE2b-256 |
a1616be490345e7d6e40674f098a7e3bb919b034cf33f5ec922cb9409cd826e4
|
File details
Details for the file blinkparse-0.1.5-py3-none-any.whl.
File metadata
- Download URL: blinkparse-0.1.5-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7463ffb673a3ecc2d93b7e610b29209d3831125359c0916c753c925d25a456e9
|
|
| MD5 |
2d6e982502abe7029e7e3b5e31b56ba4
|
|
| BLAKE2b-256 |
c183c1e33c605202cc4bf01a2559a50584d45b0103123fc3a8e858873009043a
|