$30 off During Our Annual Pro Sale. View Details »

Introduction to Clime

Introduction to Clime

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

Mosky Liu

May 20, 2013
Tweet

More Decks by Mosky Liu

Other Decks in Programming

Transcript

  1. 1 Clime Clime Mosky Mosky

  2. 2 CLI-ize ME CLI-ize ME It is what the name

    means! It is what the name means!
  3. 3 Writing A CLI program Writing A CLI program •

    It is not difficult with a library. (ex. argparse) • But it is annoying, especially for the simple tasks.
  4. 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. 5 I opened the doc of I opened the doc

    of argparse argparse, ,
  6. 6 then felt sleepy … then felt sleepy …

  7. 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. 8 But human wants are unlimited! But human wants are

    unlimited!
  9. 9 After hardworking, After hardworking,

  10. 10 Clime was released. Clime was released.

  11. 11 It converts your program It 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. 12 into a CLI program into a CLI program $

    python pyramid.py --help usage: [--squash] <story> or: draw [--squash] <story> $ python pyramid.py –-squash=5 3 * *********** *********************
  13. 13 just by adding this line: just by adding this

    line: import clime.now
  14. 14 If you like it, If you like it,

  15. 15 $ sudo pip install clime $ sudo pip install

    clime
  16. 16 It also supported aliases It also supported aliases …

    def draw(story, squash=1): '''It draws a pyramid. -s, --squash It is optional. ''' …
  17. 17 and metavars. and metavars. … def draw(story, squash=1): '''It

    draws a pyramid. -s <int>, --squash=<int> ''' …
  18. 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. 19 http://clime.mosky.tw/ http://clime.mosky.tw/ is the documentation of Clime. is the

    documentation of Clime.
  20. 20 The End The End 1. Zero configuration 2. Auto-generates

    usage 3. Supports aliases and metavars 4.sudo pip install clime 5. http://clime.mosky.tw/