From e0838bb9689e79c527f3ace8d46d191347799d51 Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Sun, 8 Feb 2015 00:18:03 +0000 Subject: [PATCH] Correct port precedence --- honcho/command.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/honcho/command.py b/honcho/command.py index d8c951f..75e0115 100644 --- a/honcho/command.py +++ b/honcho/command.py @@ -82,11 +82,12 @@ def command_export(args): procfile = _procfile(procfile_path) env = _read_env(procfile_path, args.env) concurrency = _parse_concurrency(args.concurrency) + port = _choose_port(args, env) processes = environ.expand_processes(procfile.processes, concurrency=concurrency, env=env, - port=args.port) + port=port) export_ctor = export_choices[args.format].load() export = export_ctor() @@ -119,8 +120,8 @@ def command_export(args): default="/var/log/APP", type=str, metavar='DIR') parser_export.add_argument( '-p', '--port', - help='port to use as the base for this application in exported config file', - default=5000, type=int, metavar='N') + help="starting port number (default: 5000)", + default=argparse.SUPPRESS, type=int, metavar='N') parser_export.add_argument( '-c', '--concurrency', help='number of each process type to run.', @@ -188,10 +189,10 @@ def command_start(args): procfile_path = _procfile_path(args.app_root, args.procfile) procfile = _procfile(procfile_path) - port = int(os.environ.get('PORT', args.port)) concurrency = _parse_concurrency(args.concurrency) env = _read_env(procfile_path, args.env) quiet = _parse_quiet(args.quiet) + port = _choose_port(args, env) if args.processes: processes = compat.OrderedDict() @@ -223,8 +224,8 @@ def command_start(args): **_parser_defaults) parser_start.add_argument( '-p', '--port', - help="starting port number", - type=int, default=5000, metavar='N') + help="starting port number (default: 5000)", + type=int, default=argparse.SUPPRESS, metavar='N') parser_start.add_argument( '-c', '--concurrency', help='the number of each process type to run.', @@ -324,6 +325,20 @@ def _parse_quiet(desc): return result +def _choose_port(args, env): + env_port = env.pop('PORT', None) + os_env_port = os.environ.pop('PORT', None) + + if hasattr(args, 'port'): + return args.port + elif env_port is not None: + return int(env_port) + elif os_env_port is not None: + return int(os_env_port) + else: + return 5000 + + def _mkdir(path): if os.path.exists(path): return