Skip to main content

Exposing python functions to the command line.

Project description

pyopt version 0.71 - http://code.google.com/p/pyopt/

A python 3 module for command-line options with a pythonic, decorator-centric
syntax.

The following example auto-generates help with docstrings, type casting for
arguments and enforcing argument count:

import pyopt
import random

expose = pyopt.Exposer()

@expose.args
def roll_dice(number_of_faces:int, repetitions:int):
'''
Roll the dice to see if you are lucky or for general D&D pleasure.
number_of_faces - the max value of the die.
repititions - the amount of times to throw the dice.
'''
for i in range(repetitions):
print(random.randint(1, number_of_faces))


expose.run()

There are 3 modes of operation:
1. expose.args - A decorator for positional arguments.
2. expose.kwargs - A decorator for keyword arguments.
3. expose.mixed - A decorator for keyword and positional arguments.

Currently known compromises that are open to discussion, e-mail me:
1. This module was specifically designed with python 3 in mind, certain
features
can be converted to python 2.x, but the awesome ones can't.
2. Keyword command-line functions require every argument to start with a
different letter to avoid collisions.
3. Annotations aren't mandatory, I don't know if this is the right way to
go,
it's an explicity vs convenience issue.
4. Booleans can't default to false. I couldn't think of a use case for this
so tell me if you did.

License: whatever, I don't mind. Google Code made me choose so I went with
the "New BSD". If somebody has a better idea, e-mail, comment or whatnot.
Hearing from whoever uses this code would be nice, but you really shouldn't
feel obliged.

Contact me at: ubershmekel at gmail

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

pyopt-0.71.zip (6.8 kB view details)

Uploaded Source

File details

Details for the file pyopt-0.71.zip.

File metadata

  • Download URL: pyopt-0.71.zip
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyopt-0.71.zip
Algorithm Hash digest
SHA256 2c2a17a1458fc8a8f75b8f195dc9a00117cabab9f9adcaa679a171185aa48069
MD5 0b02a8575ef7c91bef887265f8eaeed7
BLAKE2b-256 4520b4bed5d63ed791a01253f888e70ad4a92c14b14d49f00431b719c2bec17d

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