1. Ask Solem Hoel
  2. Flask-Script


Flask-Script / examples / manage.py

import pprint

from flask import Flask, current_app
from flaskext.script import Manager, prompt_choices

def create_app(config=None):
    app = Flask(__name__)
    app.debug = False
    print "CONFIG", config

    app.config.from_envvar('APP_CONFIG', silent=True)

    def index():
        # deliberate error, test debug working
        assert False, "oops"

    return app

manager = Manager(create_app)

def dumpconfig():
    "Dumps config"

def output(name):
    "print something"
    print name
    print type(name)

def outputplus(name, url=None):
    "print name and url"
    print name, url

def getrolesimple():

    choices = ("member", "moderator", "admin")

    role = prompt_choices("role", choices=choices, default="member")
    print "ROLE:", role

def getrole():

    choices = (
        (1, "member"),
        (2, "moderator"),
        (3, "admin"),

    role = prompt_choices("role", choices=choices, resolve=int, default=1)
    print "ROLE:", role

@manager.option('-n', '--name', dest='name', help="your name")
@manager.option('-u', '--url', dest='url', help="your url")
def optional(name, url):
    "print name and url"
    print name, url

manager.add_option("-c", "--config", 
                   help="config file", 

if __name__ == "__main__":