This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

easycommandline.py

a solution for python command-line interfaces, inspired by tj/commander.js

Installation

$ pip install easycommandline

Option

Options are defined with the .options() method, also serving as documentation for the options. The example below parses args and options from sys.argv

# file favcolor.py

from easycommandline import program

program.version('1.0.1')
program.options(
        ('-r', '--red'),
        ('-g', '--green'),
        ('-b', '--blue'),
        ('-w', '--white'),
    )
program.parse_argv()

if program.red:
    print('- red')
if program.blue:
    print('- blue')
if program.white:
    print('- white')
$ python favcolor.py -r -w
    - red
    - white

Coercion

# file coercion.py

from easycommandline import program

def collect(value, previous_value):
    previous_value.append(value)
    return previous_value

def make_range(value):
    components = value.split('..')
    return range( int(components[0]), int(components[1]) )

def sum(value, previous_value):
    return previous_value + int(value)

program.version('1.0.1')
program.options(
        ('-r', '--recursive'),
        ('-p', '--preload', 'preload enabled'),
        ('-n', '--name', 'username'),
        ('-i', '--integer <int>', 'an integer argument', int),
        ('-f', '--float <float>', 'a float argument', float),
        ('-a', '--anotherfloat', 'another float argument', float),
        ('-c', '--collection [example]', 'collection', collect, []),
        ('-x', '--range A..B', 'range', make_range),
        ('-s', '--sum', 'the sum of numbers', sum, 0),
    )
program.parse_argv()

print('recursive  : ', program.recursive)
print('preload    : ', program.preload)
print('name       : ', program.name)
print('integer    : ', program.integer)
print('float      : ', program.float)
print('collection : ', program.collection)
print('range      : ', program.range)
print('sum        : ', program.sum)
$ python coercion.py -p --name Tracy -i 1000 --range 5..8 -s 1 2 3 4
    recursive  :  None
    preload    :  True
    name       :  Tracy
    integer    :  1000
    float      :  None
    collection :  []
    range      :  [5, 6, 7]
    sum        :  10

Command

specifies
argument required with < >
argument optional with [ ], cannot specify more than one optional argument
# file cmd.py

from easycommandline import program
import os

program.version('1.0.1')


cmd = program.cmd('cd <path>')
cmd.options(
        ('-c', '--create', 'create directory if not existed'),
        )
cmd.description('change directory')
@cmd.action
def action_for_cmd_cd(cmd, path):
    if cmd.create and not os.path.exists(path):
        os.makedirs(path)



cmd = program.cmd('start server <path> [env]')
@cmd.action
def action_for_cmd_start_server(cmd, path, env):
    print(path)
    print(env)


program.parse_argv()
$ python cmd.py cd ~/Desktop/abc -c
$ python cmd.py start server ~/Desktop/abc production

Automated –help

$ python coercion.py -h

    Usage: python coercion.py [options]

    Options:

    -h, --help                  output usage information
    -V, --version               output the version number
    -r, --recursive
    -p, --preload               preload enabled
    -n, --name                  username
    -i, --integer <int>         an integer argument
    -f, --float <float>         a float argument
    -a, --anotherfloat          another float argument
    -c, --collection [example]  collection
    -x, --range A..B            range
    -s, --sum                   the sum of numbers
Release History

Release History

1.8.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
easycommandline-1.8.1.tar.gz (6.7 kB) Copy SHA256 Checksum SHA256 Source Jul 18, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting