Skip to main content

Let you convert any module into a multi-command CLI program without any configuration.

Project description

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

Clime

Let you convert any module into a multi-command CLI program without any configuration.

The features:

  1. Zero configuration. Free you from the configuration hell.

  2. Docstring just is config. When you finish the docstring, the config of the aliases and metavars are also finished.

  3. Auto-generate the usage of each command from the functions.

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

Let me show you Clime with an example.

CLI-ize ME!

Here we have a simple script with a docstring here:

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

By adding this line,

import clime.now

… your CLI program is ready!

$ python repeat.py twice
twicetwice

$ python repeat.py -n3 thrice
thricethricethrice

And it generates the usage manual:

$ 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 show 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 repeat the message.

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

You can find more examples in the clime/examples.

See the Command.parse() for more details about the argument parsing.

Installation

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

  1. 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.

  2. Get Clime from GitHub

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

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

    to clone a Clime repository. Or download manually from GitHub.

Usage

Below illustrates the basic usage of Clime.

You have two different ways to use Clime.

  1. Insert A Line into Your Source

    Just add this line into your source

    import clime.now

    It is recommended to put the line in the if __name__ == '__main__': block.

  2. Use Clime as A Command

    clime is also an executable module. You can use it to convert a module or a stand-alone program temporarily.

    $ python -m clime TARGET

See the Program class for more usages.

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

clime-0.1.5.tar.gz (15.2 kB view details)

Uploaded Source

File details

Details for the file clime-0.1.5.tar.gz.

File metadata

  • Download URL: clime-0.1.5.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for clime-0.1.5.tar.gz
Algorithm Hash digest
SHA256 badfbf00e0c849132e843c32adb490564029962b97a92be6755438afbe120cba
MD5 2a20322ce0a9965b7a2d8d0671dd7e87
BLAKE2b-256 4f6bf62c7306424090e42a77f57a90cc3c300fe9a6dc59b3463507334c707762

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