Monolith是一个基于argparse的命令行接口框架
monolith的Python项目详细描述
整体石
Monolith是创建命令行工具的简单框架。子命令是 基于类(方法和实现的一部分受到django的启发 但是monolith使用的是argparse而不是optparse。
支持的python版本有2.6/2.7、3.2+和pypy。
最新的文档可以在https://monolith.readthedocs.org/en/latest/找到。
示例
#!/usr/bin/env python """ Example of how to create git-like execution manager with monolith. This is completely fake command. """ from __future__ import print_function from monolith.cli import SimpleExecutionManager from monolith.cli import BaseCommand from monolith.cli import LabelCommand from monolith.cli import arg class AddCommand(LabelCommand): def handle_label(self, label, namespace): print("A %s" % label) class CommitCommand(BaseCommand): args = BaseCommand.args + [ arg('-a', '--add', action='store_true', default=False), arg('-m', '--message', help="Commit's message", required=True), ] def handle(self, namespace): print('Commit message: %r' % namespace.message) if namespace.add: print(' * add switch given!') def main(): manager = SimpleExecutionManager('mygit', commands={ 'add': AddCommand, 'commit': CommitCommand, }) manager.execute() if __name__ == '__main__': main()