view piecrust/commands/builtin/serving.py @ 164:4534ccbdd2a3

find: Fix the `find` command, add more options. The `--endpoint` option doesn't make any sense anymore since page sources could have non-file-system endpoints. This was replaced with `--name` to match source names instead. Also added `--include-theme`, with filtering out theme pages by default, and `--exact` to explicitely match the given pattern, with matching anything that contains the pattern by default.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 01 Jan 2015 21:34:06 -0800
parents 50b65c700c96
children f3aa511eef99
line wrap: on
line source

import logging
from piecrust.serving import Server
from piecrust.commands.base import ChefCommand


logger = logging.getLogger(__name__)


class ServeCommand(ChefCommand):
    def __init__(self):
        super(ServeCommand, self).__init__()
        self.name = 'serve'
        self.description = "Runs a local web server to serve your website."

    def setupParser(self, parser, app):
        parser.add_argument('-p', '--port',
                help="The port for the web server",
                default=8080)
        parser.add_argument('-a', '--address',
                help="The host for the web server",
                default='localhost')
        parser.add_argument('--use-reloader',
                help="Restart the server when PieCrust code changes",
                action='store_true')

    def run(self, ctx):
        server = Server(
                ctx.app.root_dir,
                host=ctx.args.address,
                port=ctx.args.port,
                debug=ctx.args.debug,
                use_reloader=ctx.args.use_reloader)
        server.run()