Skip to main content

command line parsing speedster

Project description

Opster is a command line options 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,
         no_newline=('n', False, 'don\'t print a newline')):
    'Simple echo program'
    sys.stdout.write(message)
    if not no_newline:
        sys.stdout.write('\n')

if __name__ == '__main__':
    main()

Running this program will print the help:

echo.py [-n] MESSAGE

Simple echo program

options:

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

As you can see, here we have defined option to not print newline: keyword argument name is a long name for option, default value is a 3-tuple, containing short name for an option (can be empty), default value (on base of which processing is applied - see description) and a help string.

Underscores in long names are converted into dashes.

If you are calling a command with option using long name, you can supply it partially. In this case it could look like ./echo.py --nonew. This is also true for subcommands: read about them and everything else you’d like to know in documentation.

Changelog

0.9.12

  • fixed trouble with non-ascii characters in docstrings

0.9.11

  • fixed exceptions handling

  • autocompletion improvements (skips middleware, ability of options completion)

0.9.10

  • if default value of an option is a fuction, always call it (None is passed in case when option is not supplied)

  • always call a function if it’s default argument for an option

  • some cleanup with better support for python 3

  • initial support for autocompletion (borrowed from PIP)

0.9.9

  • Now it’s possible to call commands as regular function, where every non-supplied option will receive proper default (defined in option spec)

  • Globaloptions were simply dropped after parsing, fold them in regular options

  • Replace _ with - in command names, same as in options names

  • Respect empty strings as usage

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.12.tar.gz (8.5 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for opster-0.9.12.tar.gz
Algorithm Hash digest
SHA256 2ca57eda115e49805ca8c950a15f2a1f66a89b9db14b515198d9413a473fffcb
MD5 eed94b4cd16752e426d115cb0843f1d2
BLAKE2b-256 09a6bc63924f6b1fb0332452afd94008f137a0a443dfa6ecc1c90a06064bbfcb

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