Skip to content

lukassup/python-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://travis-ci.org/lukassup/python-cli.svg?branch=master

crud-cli

crud-cli is a simple Python CLI CRUD application skeleton

Installation

Supported versions of Python are: 2.6, 2.7, 3.4, 3.5 and 3.6. The recommended way to install this package is via pip.

$ git clone https://github.com/lukassup/python-cli.git
$ pip install ./python-cli

For instructions on installing python and pip see "The Hitchhiker's Guide to Python" Installation Guides.

Alternatively use easy_install:

$ git clone https://github.com/lukassup/python-cli.git
$ easy_install ./python-cli

Usage

Create CLI scripts quickly using function decorators

from crud_cli import CLI

cli = CLI()

@cli.command('create')
@cli.option('name')
@cli.option('-s', '--size', type=int, choices=range(3))
def create_command(name, size):
    """Creates a resource."""
    print('creating resource')
    print('name: %r' % name)
    print('size: %r' % size)

cli.run()

Script help and argument parsing is performed by argparse library behind the curtains

$ crud-cli create --help
usage: crud-cli create [-h] [-v | -q] [-s {0,1,2}] name

Creates a resource.

positional arguments:
name

optional arguments:
-h, --help            show this help message and exit
-v, --verbose         more verbose
-q, --quiet           less verbose
-s {0,1,2}, --size {0,1,2}

Development

Install the python-cli package in editable mode using pip:

$ git clone https://github.com/lukassup/python-cli.git
$ pip install -e ./python-cli

Testing

Run the tests:

$ git clone https://github.com/lukassup/python-cli.git
$ cd python-cli
$ python2 setup.py test
$ python3 setup.py test

About

Python CLI example script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages