introduction to clime

20
1 Clime Clime Mosky Mosky

Upload: mosky-liu

Post on 25-May-2015

3.862 views

Category:

Technology


0 download

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

Page 1: Introduction to Clime

1

ClimeClimeMoskyMosky

Page 2: Introduction to Clime

2

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

Page 3: Introduction to Clime

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.

Page 4: Introduction to Clime

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

...

Page 5: Introduction to Clime

5

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

Page 6: Introduction to Clime

6

then felt sleepy … then felt sleepy …

Page 7: Introduction to Clime

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]]()

Page 8: Introduction to Clime

8

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

Page 9: Introduction to Clime

9

After hardworking,After hardworking,

Page 10: Introduction to Clime

10

Clime was released.Clime was released.

Page 11: Introduction to Clime

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)

Page 12: Introduction to Clime

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

*

***********

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

Page 13: Introduction to Clime

13

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

import clime.now

Page 14: Introduction to Clime

14

If you like it,If you like it,

Page 15: Introduction to Clime

15

$ sudo pip install clime$ sudo pip install clime

Page 16: Introduction to Clime

16

It also supported aliasesIt also supported aliases

def draw(story, squash=1):

'''It draws a pyramid.

-s, --squash It is optional.

'''

Page 17: Introduction to Clime

17

and metavars.and metavars.

def draw(story, squash=1):

'''It draws a pyramid.

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

'''

Page 18: Introduction to Clime

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>

Page 19: Introduction to Clime

19

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

Page 20: Introduction to 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/