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

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

The main features:

  1. It works well with zero configuration. Free you from the configuration hell.

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

  3. It generates the usage of each command from the functions 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.

Here 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 adding this line,

import clime.now

… your CLI program is ready!

$ python repeat.py twice
twicetwice

$ python repeat.py --times=3 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.

This page, Command.parse, describes how Clime parses the arguments.

If you are interesting in the aliases or the metavariables which Clime provides, read Command for more infomation.

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 latest version of Clime, use

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

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

Usage

You have two different ways to use Clime.

  1. Insert A Line into Your Source Code

    Just add this line into your source code:

    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

If you want to know how to customize the program, read Program for more infomation.

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.9.tar.gz (18.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for clime-0.1.9.tar.gz
Algorithm Hash digest
SHA256 95e4d9c0b48f3d5d541647aa8a5031f5aa9ba2fc6b4b4445cc03853b603fcdb3
MD5 fd6cf3918c3292823fb52a5b28e5aee6
BLAKE2b-256 f16884864c5ec72f6a49fb1cce5a16948e609a0b31c6f465ad30142a246921ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page