Skip to content

Adding Controllers #35

Description

@neithere

Typical case:

class Controller:
    db = {1: 'foo', 2: 'bar'}

    def index(self):
        return self.db.keys()

    def detail(self, key):
        return self.db[key]

c = Controller()

# now
parser.add_commands([c.index, c.detail])

# ideally
parser.add_controller(c)
parser.add_controller(c, namespace='my-controller')

# ideally — paranoid mode (requires an @expose decorator on methods)
parser.add_controller(c, only_exposed=True)

Modules can be added in the same way despite they are unlikely to be controllers:

# commands.py

def foo(): pass

def bar(): pass

# cli.py

import commands

parser.add_controller(commands)

# paranoid mode; really makes sense here
parser.add_controller(commands, only_exposed=True)

Note: This issue has been automatically migrated from Bitbucket
Created by @neithere on 2013-01-10 03:39:11+00:00, last updated: 2013-01-30 01:10:54+00:00

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions