Skip to main content

monolith is an argparse based command line interface framework

Project description

https://secure.travis-ci.org/lukaszb/monolith.png?branch=master

Monolith

monolith is simple framwork for creating command line tools. Subcommands are class based (approach and part of implementation was inspired by Django management commands, however monolith uses argparse instead of optparse).

Supported Python versions are 2.6/2.7, 3.2+ and PyPy.

Example

#!/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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monolith-0.3.0.tar.gz (11.6 kB view details)

Uploaded Source

File details

Details for the file monolith-0.3.0.tar.gz.

File metadata

  • Download URL: monolith-0.3.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for monolith-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a2337a6b77a54dc4e9943fcffb2668e3544775d2da8de681a391d5a010c52d8e
MD5 9b410f6f2901729e3dcc305fab60f383
BLAKE2b-256 bf0e6e97e9fc3eacd35bf1a71715f01132c0ccbfd86cf3c3952ba78aefa26d5f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page