Skip to main content

command line parsing speedster

Project description

Opster is a command line parser, intended to make writing command line applications easy and painless. It uses built-in Python types (lists, dictionaries, etc) to define options, which makes configuration clear and concise. Additionally it contains possibility to handle subcommands (i.e. hg commit or svn update).

Quick example

That’s an example of an option definition:

import sys
from opster import command

@command(usage='%name [-n] MESSAGE')
def main(message,
         nonewline=('n', False, 'don\'t print a newline')):
    'Simple echo program'
    sys.stdout.write(message)
    if not nonewline:
        sys.stdout.write('\n')

if __name__ == '__main__':
    main()

Running this program will print the help:

echo.py [-n] MESSAGE

Simple echo program

options:

 -n --nonewline  don't print a newline
 -h --help       show help

I think this mostly describes what’s going on, except that I’d like to mention one interesting feature - if you are using long name for option, you can use only partial name, for example ./echo.py --nonew a is valid command line. This is also true for subcommands: read about that and everything else you’d like to know in documentation.

Changelog

0.9.8

Fixed bug with option names clashing with name of arguments for call_cmd.

0.9.7

Library renamed to opster.

0.9.6

  • Checks for option definition: long name should be specified always, short name should be 1 character in length if available.

  • More specific argument name in guessed usage (this happens if you have not specified usage for command).

  • Ability to add global decorator for all commands. See test.py in repository for example: ui object, to handle verbose/quiet options.

0.9.5

Fixed bug, which prevented programs to work without arguments (displayed help instead) if they are not using subcommands.

0.9.4

  • Ability to hide subcommands from help listing.

  • Append program name to subcommand usage.

0.9.3

Minor fix for setup.py, to avoid troubles with installing when there is no docs in package.

0.9.2

Ability to call commands as regular functions, using arguments and keyword arguments.

0.9.1

Fixed problem with multiple help options in subcommands

0.9

Initial version

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

opster-0.9.8.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file opster-0.9.8.tar.gz.

File metadata

  • Download URL: opster-0.9.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for opster-0.9.8.tar.gz
Algorithm Hash digest
SHA256 4016cdc60a3af0144bba152ab3ec6b389b3e77bde23c29f14f2be864934ad8d3
MD5 f4a12a1eda402ac55b6f17ad47e0609d
BLAKE2b-256 d35a156719e9ed145fe68e09fa79abc0dbe5b8facc91eda84c16bc6beb68fc0b

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