Easily convert your Python functions into multi-command CLI program.
Project description
Clime is a simple Python module to let you convert a Python program contains functions into a multi-command CLI program.
See the full documentaion on http://docs.mosky.tw/clime/ .
Installation
Clime is hosted on two different platform, 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 lastest version of Clime, use
$ git clone git://github.com/moskied/clime.git
to clone a Clime repository. Or download manually from GitHub.
CLI-ize ME!
Here is the basic usage of Clime.
You have two different ways to use Clime.
Insert Lines into Source
Just add two lines below into your source
import clime clime.main()
Recommend to put the codes into the if __name__ == '__main__': block.
Use clime.py as A Command
clime.py is also an executable script. Use it to convert a moudle temporarily.
For convenience, make a command for clime.py
$ sudo ln -s /usr/local/lib/python<VERSION>/dist-packages/clime.py /usr/bin/clime $ sudo chmod 755 /usr/bin/clime
Then, you can use clime as a normal command
$ clime <module_name> <args_for_module>
Examples
Here is a example of a script uses Clime:
# file: example/singlecmd.py '''Here is docstring of module.''' def onlyme(s, b=True, l=None): '''Here is docstring of function.''' print 's:', s print 'b:', b print 'l:', l if __name__ == '__main__': import clime clime.main()
After added the last 2 lines, this script is a CLI program now. Try to use it on shell.
Call the program with –help
$ python singlecmd.py --help usage: singlecmd.py [-b] [-l VAL] s or: singlecmd.py onlyme [-b] [-l VAL] s Here is docstring of module.
Call the program with Command and –help
$ python singlecmd.py onlyme --help usage: singlecmd.py onlyme [-b] [-l VAL] s Here is docstring of function.
The different behaviors decide by default value
$ python singlecmd.py test -b -loption_arg s: test b: False l: option_arg
Duplicate options
$ python singlecmd.py test -bbb -l one -l two -l three s: test b: 3 l: ['one', 'two', 'three']
See the clime.Command.parse section for more details about argument parsing.
More examples are in the clime/examples.
The basic usage of Clime is end here. If you want to know more details or help Clime, please visit Take a Deeper Look at Clime.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file clime-0.1.2.tar.gz
.
File metadata
- Download URL: clime-0.1.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ed2144e6f50bd6e78d63b9c4b8cd6f59c2f9fd5bec3617235eb04cdad3d673f |
|
MD5 | cc60538b83c5349ba0556e853266948d |
|
BLAKE2b-256 | fb107cdbed452fc114c0180e892066c4ac02463308ff4dd5a44672aa525f4622 |