Add CLI option for the server port.

This commit is contained in:
Jonathan Bernard
2025-07-26 20:22:33 -05:00
parent 5674c1e95c
commit 0e5cd036ef
+3 -2
View File
@@ -8,7 +8,8 @@ Usage:
Options: Options:
-c, --config <cfgFile> Use the given config file (defaults to ./short-url.cfg.json) -c, --config <cfgFile> Use the given config file (defaults to ./short_url.cfg.json)
--port <port> Bind the server to the given port (defaults to 80)
--debug Enable debug-level logging. --debug Enable debug-level logging.
--trace Enable trace-level logging (takes precedence over --debug). --trace Enable trace-level logging (takes precedence over --debug).
""" """
@@ -29,7 +30,7 @@ type
proc loadConfig(args: Table[string, Value]): ShortUrlsConfig = proc loadConfig(args: Table[string, Value]): ShortUrlsConfig =
let cfgFile = let cfgFile =
if args["--config"]: $args["--config"] if args["--config"]: $args["--config"]
else: findConfigFile("short-url.cfg.json") else: findConfigFile("short_url.cfg.json")
result.cfg = initCombinedConfig(filename = cfgFile, docopt = args) result.cfg = initCombinedConfig(filename = cfgFile, docopt = args)
result.port = parseInt(result.cfg.getVal("port", "80")) result.port = parseInt(result.cfg.getVal("port", "80"))