From 44f20904b2795207fa50149cd5e2b11af005377b Mon Sep 17 00:00:00 2001 From: Morten Siebuhr Date: Mon, 4 Jun 2018 13:56:27 +0200 Subject: [PATCH] Read all relevant options from config file too --- config/default.yml | 3 +++ main.js | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config/default.yml b/config/default.yml index e38c655..683d97e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1,5 +1,8 @@ Cache: defaultModule: "cache_fs" + #port: 8126 + #workers: 2 + #log-level: 3 options: cache_ram: cachePath: ".cache_ram" diff --git a/main.js b/main.js index 4896fab..f99ea3a 100755 --- a/main.js +++ b/main.js @@ -27,15 +27,18 @@ function collect(val, memo) { } const defaultCacheModule = config.get("Cache.defaultModule"); +const defaultCachePort = config.has('Cache.port') ? config.get('Cache.port') : consts.DEFAULT_PORT; +const defaultLogLevel = config.has('Cache.log-level') ? config.get('Cache.log-level') : consts.DEFAULT_LOG_LEVEL; +const defaultWorkers = config.has('Cache.workers') ? config.get('Cache.workers') : consts.DEFAULT_WORKERS program.description("Unity Cache Server") .version(VERSION) .allowUnknownOption(true) - .option('-p, --port ', 'Specify the server port, only apply to new cache server', myParseInt, consts.DEFAULT_PORT) + .option('-p, --port ', 'Specify the server port, only apply to new cache server', myParseInt, defaultCachePort) .option('-c --cache-module [path]', 'Use cache module at specified path', defaultCacheModule) .option('-P, --cache-path [path]', 'Specify the path of the cache directory') - .option('-l, --log-level ', 'Specify the level of log verbosity. Valid values are 0 (silent) through 5 (debug)', myParseInt, consts.DEFAULT_LOG_LEVEL) - .option('-w, --workers ', 'Number of worker threads to spawn', zeroOrMore, consts.DEFAULT_WORKERS) + .option('-l, --log-level ', 'Specify the level of log verbosity. Valid values are 0 (silent) through 5 (debug)', myParseInt, defaultLogLevel) + .option('-w, --workers ', 'Number of worker threads to spawn', zeroOrMore, defaultWorkers) .option('-m --mirror [host:port]', 'Mirror transactions to another cache server. Can be repeated for multiple mirrors', collect, []) .option('--dump-config', 'Write the active configuration to the console') .option('--save-config [path]', 'Write the active configuration to the specified file and exit. Defaults to ./default.yml')