Code Monkey home page Code Monkey logo

clime's Introduction

https://travis-ci.org/moskytw/clime.png https://pypip.in/v/clime/badge.png https://pypip.in/d/clime/badge.png

The full version of this documentaion is at clime.mosky.tw.

Clime

Clime lets you convert any module into a multi-command CLI program with zero configuration.

The main features:

  1. It works well with zero configuration. Free you from the configuration hell.
  2. Docstring (i.e., help text) is just configuration. When you finish your docstring, the configuration of aliases and metavars is also finished.
  3. It generates usage for each command automatically.

It is a better choice than the heavy optparse or argparse for most of the CLI tasks.

CLI-ize ME!

Let me show you Clime with an example.

We have a simple script with a docstring here:

# file: repeat.py

def repeat(message, times=2, count=False):
    '''It repeats the message.

    options:
        -m=<str>, --message=<str>  The description of this option.
        -t=<int>, --times=<int>
        -c, --count
    '''

    s = message * times
    return len(s) if count else s

After we add this line:

import clime.now

Our CLI program is ready!

$ python repeat.py twice
twicetwice

$ python repeat.py --times=3 thrice
thricethricethrice

It also generates a pretty usage for this script:

$ python repeat.py --help
usage: [-t <int> | --times=<int>] [-c | --count] <message>
   or: repeat [-t <int> | --times=<int>] [-c | --count] <message>

If you have a docstring in your function, it also shows up in usage manual with --help.

$ python repeat.py repeat --help
usage: [-t <int> | --times=<int>] [-c | --count] <message>
   or: repeat [-t <int> | --times=<int>] [-c | --count] <message>

It repeats the message.

options:
    -m=<str>, --message=<str>  The message.
    -t=<int>, --times=<int>
    -c, --count

You can find more examples in the clime/examples.

Command describes more about how it works.

Installation

Clime is hosted on two different platforms, PyPI and GitHub.

Install from PyPI

Install Clime from PyPI for a stable version:

$ sudo pip install clime

If you don't have pip, execute

$ sudo apt-get install python-pip

to install pip on Debian-base Linux distribution.

Get Clime from GitHub

If you want to follow the latest version of Clime, use

$ git clone git://github.com/moskytw/clime.git

to clone a Clime repository, or download manually from GitHub.

clime's People

Contributors

absolutelynowarranty avatar moskytw avatar pjw91 avatar takano32 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.