Skip to main content

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.Arguments object
  • args is a list of blinkparse.Argument objects
  • commands is a list of blinkparse.Command objects
  • description is a description to show at the top of the help page
  • commandRequired is whether the program requires a command to be passed in
  • noOperands is whether the program is allowed to take operands
  • parse(inputArgs=None)
    • Returns a blinkparse.Arguments object
    • inputArgs is a list of the arguments to parse. This defaults to sys.argv[1:]

Argument(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 in
  • description is 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
  • name is the name of the command
  • args is a list of blinkparse.CommandArgument objects that the command takes
  • CommandArgument(name, options=None, required=True)
    • name is the name of the command argument
    • options 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 = 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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blinkparse-0.1.5-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

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

Hashes for blinkparse-0.1.5.tar.gz
Algorithm Hash digest
SHA256 81cc224c38e452aa61f927baf568610dbaf949089fe9f649151d33d687b6b271
MD5 9e2c4f4a7541aa5e499cd26aa4f3a31e
BLAKE2b-256 a1616be490345e7d6e40674f098a7e3bb919b034cf33f5ec922cb9409cd826e4

See more details on using hashes here.

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

Hashes for blinkparse-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7463ffb673a3ecc2d93b7e610b29209d3831125359c0916c753c925d25a456e9
MD5 2d6e982502abe7029e7e3b5e31b56ba4
BLAKE2b-256 c183c1e33c605202cc4bf01a2559a50584d45b0103123fc3a8e858873009043a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page