• Stars
    star
    151
  • Rank 244,582 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATION: Convert functions into multi-command program breezily.

DEPRECATION

This project is deprecated and is not maintained anymore. You may like Click or Typer. Thank you for the years. โค๏ธ

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.

More Repositories

1

zipcodetw

Find Taiwan ZIP code by address fuzzily.
Python
281
star
2

uniout

Never see escaped bytes in output.
Python
158
star
3

mosql

Build SQL with native Python data structure smoothly.
Python
140
star
4

mosky-mini-configs

The configs just work. โœจ
Shell
91
star
5

hypothesis-testing-with-python

True difference or noise? ๐Ÿ“Š
Jupyter Notebook
70
star
6

mosky.vim

DEPRECATE: This repo is merged into moskytw/mosky-mini-configs.
Vim Script
47
star
7

elegant-concurrency-lab

Make concurrency elegant with channels.
Python
43
star
8

practicing-python-3

Learn Python from zero to intermediate! ๐Ÿš€
Jupyter Notebook
37
star
9

data-science-with-python

Introduce data science in plain Python. ๐Ÿงช
Jupyter Notebook
35
star
10

git-count

Python
28
star
11

revivalkit

Python
26
star
12

slak

Collect data from Slack like a pro. โšก๏ธ
Python
24
star
13

statistical-regression-with-python

Explain & predict! ๐Ÿ“ˆ
Jupyter Notebook
15
star
14

postbox

Python
13
star
15

mining-ptt-news

What kind of news will be voted down on PTT?
Jupyter Notebook
13
star
16

luthadel.vim

A simple but ardent Vim color scheme.
Vim Script
11
star
17

nginx-contrib-vim

Make Vim have better nginx.conf support.
Vim Script
9
star
18

enhancedyaml

Python
8
star
19

cython-lab

Python
7
star
20

uwsgi-emperor

7
star
21

coding-is-magic

Magic! โœจ
Jupyter Notebook
5
star
22

examples-for-learning-python-from-data

Python
4
star
23

concurrency-lab

Python
4
star
24

memo-app

JavaScript
4
star
25

multi-celeryd

4
star
26

tacit

Python
2
star
27

snack

Python
1
star
28

tagit.vim

It is a vim plugin handles tags in background. Let you enjoy the benfits of tags without addational effort.
Vim Script
1
star
29

vim-color-scheme-template-generator

Generate Vim's color scheme template precisely.
Python
1
star
30

examples-for-programming-with-python

Python
1
star