introduction to clime

Post on 25-May-2015

3.863 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Clime is a Python library which lets you convert any module into a multi-command CLI program without any configuration. It is a short tour of Clime. The full documentation of Clime: http://clime.mosky.tw/.

TRANSCRIPT

1

ClimeClimeMoskyMosky

2

CLI-ize MECLI-ize MEIt is what the name means!It is what the name means!

3

Writing A CLI programWriting A CLI program

● It is not difficult with a library. (ex. argparse)● But it is annoying,

especially for the simple tasks.

4

At one midnight ...At one midnight ...

I was thinking about the schema of the database.● initdb.py● cleardb.py● dropdb.py

...

● db.py init● db.py clear● db.py drop

...

5

I opened the doc of I opened the doc of argparseargparse,,

6

then felt sleepy … then felt sleepy …

7

It shouldn't be long!It shouldn't be long!

# file: db.py

def init():

pass

def clear():

pass

def drop():

pass

if __name__ == '__main__':

import sys

locals()[sys.argv[1]]()

8

But human wants are unlimited!But human wants are unlimited!

9

After hardworking,After hardworking,

10

Clime was released.Clime was released.

11

It converts your programIt converts your program

# file: pyramid.py

def draw(story, squash=1):

ground_len = 1 + (story-1) * squash * 2

for i in range(1, ground_len+1, squash*2):

print ('*'*i).center(ground_len)

12

into a CLI programinto a CLI program

$ python pyramid.py --help

usage: [--squash] <story>

or: draw [--squash] <story>

$ python pyramid.py –-squash=5 3

*

***********

*********************

13

just by adding this line:just by adding this line:

import clime.now

14

If you like it,If you like it,

15

$ sudo pip install clime$ sudo pip install clime

16

It also supported aliasesIt also supported aliases

def draw(story, squash=1):

'''It draws a pyramid.

-s, --squash It is optional.

'''

17

and metavars.and metavars.

def draw(story, squash=1):

'''It draws a pyramid.

-s <int>, --squash=<int>

'''

18

It is also an executable module.It is also an executable module.

$ python -m clime math

usage: acos <x>

or: acosh <x>

or: asin <x>

or: asinh <x>

or: atan <x>

19

http://clime.mosky.tw/http://clime.mosky.tw/is the documentation of Clime.is the documentation of Clime.

20

The EndThe End

1. Zero configuration

2. Auto-generates usage

3. Supports aliases and metavars

4.sudo pip install clime

5. http://clime.mosky.tw/

top related