A python library for parsing command line arguments
Project description
BlinkParse
A python library for parsing command line arguments
Installation
pip install --user blinkparse
Usage
parse(args=[], commands=[], description='')
- Returns a
blinkparse.Arguments
object args
is a list ofblinkparse.Argument
objectscommands
is a list ofblinkparse.Command
objectsdescription
is a description to show at the top of the help page
Argument(self, name, shortName=None, takesValue=False, required=False, description=None)
name
is the argument name used in the long syntax (--myArg
,--myArg=myValue
)shortName
is the argument name used in the long syntax (-a
,-a myValue
)takesValue
is whether the argument takes a input (see above)required
makes the blinkparse raise an error if the argument isn't passed indescription
is a description to show in the help page
Command(self, 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
name
is the name of the commandargs
is a list ofblinkparse.CommandArgument
objects that the command takesCommandArgument(self, name, options=None, required=True)
name
is the name of the command argumentoptions
is a list of allowed options for the argument (defaults to everything)required
makes blinkparse raise an error if the command argument isn't passed in
aliases
is a list of other names for the command
Full example
from blinkparse import *
args = parse(
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
'''
)
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.0.6.tar.gz
(3.3 kB
view hashes)
Built Distribution
blinkparse-0.0.6-py3-none-any.whl
(16.9 kB
view hashes)
Close
Hashes for blinkparse-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79faa52103e2864b7ab280eb9103d3e796a5b0b76408a8f5372e85f253c2f8ec |
|
MD5 | 05501c23e2dfba905cacdc3b568b005e |
|
BLAKE2b-256 | 451a9c89d3a106131af6e07caa07eaae5796789d2730e0fc84f0e5f2d6783e73 |