Package: jumon
jumonis a small framework for sub commands.The jumon is a small framework for implementing the sub command.
You can be implemented sub commands,
as the hierarchial structure of the sub modules in the packages.
It finds importable sub module from the arguments passed,
Runs main function in the importable sub module with arguments.You can be displayed the hierarchial structure of the sub commands
with tree command etc, because it be implementing sub commands as
the hierarchial structure of the sub module.
It will be easy to see where sub command has been implemented.Please consider to usejumon, if you are trying to implement the
sub commands.InstallingUsesetup.pyin the source code root directory:$ python setup.py installby pip (from PyPI)$ pip install jumonHow to useThis is a description of how to use the jumon.
Let create a package called “testcmd”,
and sub package called “testcmd.command”.$ mkdir testcmd
$ touch testcmd/__init__.py
$ mkdir testcmd/commandLet implementing sub commands in “testcmd.command” subordinate.First, create top level command.:$ touch testcmd/command/__init__.pytestcmd/command/__init__.py:import jumon

def main():
    jumon.entry(__name__)Under this package is the search range of sub commands.Next, create sub command.:$ touch testcmd/command/aaa.pytestcmd/command/aaa.py:def main(argv):
    print 'OK'
    return 0This commamd is printed string “OK”, and end with exit code 0.You can be implemented sub command of sub command.:$ mkdir testcmd/command/bbb
$ touch testcmd/command/bbb/__init__.py
$ touch testcmd/command/bbb/ccc.pytestcmd/command/bbb/__init__.py:def main(argv):
    print 'bbb'
    return 1testcmd/command/bbb/ccc.py:def main(argv):
    print 'ccc'
    return 2I implemented sub commands, called “bbb” and “bbb ccc”.
This commamd “bbb” is printed string “bbb”, and end with exit code 1.
This commamd “bbb ccc” is printed string “ccc”, and end with exit code 2.Next, install “testcmd”.:$ cp testcmd $SITE_PACKAGES -RLast, create command.:$ touch test.pytest.py:#! /usr/bin/env python
import testcmd.command

def main():
    testcmd.command.main()

if __name__ == '__main__':
    main()Add permission:$ chmod 755 test.pyRun, displayed usage.:$ ./test.py
Usage: test.py [options]

test.py: error: Command Not Found:Run sub command “aaa”.:$ ./test.py aaa
OK
$ echo $?
0Run sub command “bbb”.:$ ./test.py bbb
bbb
$ echo $?
1Run sub command “bbb ccc”.:$ ./test.py bbb ccc
ccc
$ echo $?
2Do you want to created command with setup.py?setup.py:#-*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
    name='testcmd',
    version='1',
    license='BSD',
    author='TakesxiSximada',
    author_email='takesxi.sximada@gmail.com',
    packages=find_packages(),
    entry_points = """\
    [console_scripts]
    testcmd = testcmd.command:main
    """
)This is important:entry_points = """\
[console_scripts]
testcmd = testcmd.command:main
"""Do you want to transparenting the undefined options?You can usejumon.TransparentOptionParser()class.>>> import jumon
>>> parser = jumon.TransparentOptionParser()
>>> opts, args = parser.parse_args(['-f', '-n', '1'])
>>> args
['-f', '-n', '1']RequirementsPython 2.6 or laterr (not supprt 3.x)LicenseApache License 2.0