From ffff29eaaf908abc7ede8f555e1f1f8942891e24 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Sat, 14 Sep 2013 15:06:04 -0400 Subject: [PATCH] CLI defaults for 'serve' override settings from markdoc.yaml --- src/markdoc/cli/commands.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/markdoc/cli/commands.py b/src/markdoc/cli/commands.py index 10bfd78..fbf3b42 100644 --- a/src/markdoc/cli/commands.py +++ b/src/markdoc/cli/commands.py @@ -327,12 +327,16 @@ def serve(config, args): log = logging.getLogger('markdoc.serve') app = MarkdocWSGIApplication(config) - config['server.port'] = args.port - config['server.num-threads'] = args.num_threads + if args.port: + config['server.port'] = args.port + if args.num_threads: + config['server.num-threads'] = args.num_threads if args.server_name: config['server.name'] = args.server_name - config['server.request-queue-size'] = args.queue_size - config['server.timeout'] = args.timeout + if args.queue_size: + config['server.request-queue-size'] = args.queue_size + if args.timeout: + config['server.timeout'] = args.timeout if args.interface: if not IPV4_RE.match(args.interface): serve.parser.error('invalid interface specifier: %r' % args.interface) @@ -349,16 +353,19 @@ def serve(config, args): log.info('Shutting down gracefully') server.stop() -serve.parser.add_argument('-p', '--port', type=int, default=8008, +# Don't set defaults here because they will override the user's +# settings in markdoc.yaml. Set them in server.py instead. + +serve.parser.add_argument('-p', '--port', type=int, help="Listen on specified port (default is 8008)") -serve.parser.add_argument('-i', '--interface', default=None, +serve.parser.add_argument('-i', '--interface', help="Bind to specified interface (defaults to loopback only)") -serve.parser.add_argument('-t', '--num-threads', type=int, default=10, metavar='N', +serve.parser.add_argument('-t', '--num-threads', type=int, metavar='N', help="Use N threads to handle requests (default is 10)") -serve.parser.add_argument('-n', '--server-name', default=None, metavar='NAME', +serve.parser.add_argument('-n', '--server-name', metavar='NAME', help="Use an explicit server name (default to an autodetected value)") -serve.parser.add_argument('-q', '--queue-size', type=int, default=5, metavar='SIZE', +serve.parser.add_argument('-q', '--queue-size', type=int, metavar='SIZE', help="Set request queue size (default is 5)") -serve.parser.add_argument('--timeout', type=int, default=10, +serve.parser.add_argument('--timeout', type=int, help="Set the socket timeout for connections (default is 10)")