Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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. 2 CLI-ize ME CLI-ize ME It is what the name

    means! It is what the name means!
  2. 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.
  3. 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 ...
  4. 5 I opened the doc of I opened the doc

    of argparse argparse, ,
  5. 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]]()
  6. 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)
  7. 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 * *********** *********************
  8. 16 It also supported aliases It also supported aliases …

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

    draws a pyramid. -s <int>, --squash=<int> ''' …
  10. 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> …
  11. 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/