From a01cdf7896815a3ade9ddb03d091a66c3b910549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 10 Jun 2020 22:55:01 +0200 Subject: Add --config flag. --- module/main.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'module/main.scm') diff --git a/module/main.scm b/module/main.scm index aa4a2dac..4067bd82 100644 --- a/module/main.scm +++ b/module/main.scm @@ -51,7 +51,9 @@ (br) (b "Should NOT be used in production."))) - ;; TODO --config flag for loading alternate configuration file. + (config (value #t) + (description + "Path to alterantive configuration file to load instead of the default one. ")) ;; Techical note: ;; Guile's getopt doesn't support repeating keys. Thereby the small jank, @@ -110,16 +112,24 @@ (define opts (getopt-long args (getopt-opt options) #:stop-at-first-non-option #t)) (define stprof (option-ref opts 'statprof #f)) (define repl (option-ref opts 'repl #f)) + (define altconfig (option-ref opts 'config #f)) (when stprof (statprof-start)) (cond [(eqv? #t repl) (repl-start (format #f "~a/calp-~a" (runtime-dir) (getpid)))] [repl => repl-start]) - (let ((config-file (format #f "~a/.config/calp/config.scm" - (getenv "HOME")))) - (when (file-exists? config-file) - (primitive-load config-file))) + (if altconfig + (begin + (if (file-exists? altconfig) + (primitive-load altconfig) + (throw 'option-error "Configuration file ~a missing" altconfig))) + ;; if not altconfig, then regular config + (let ((config-file (format #f "~a/.config/calp/config.scm" + (getenv "HOME")))) + (when (file-exists? config-file) + (primitive-load config-file)))) + ;; TODO this doesn't stop at first non-option, meaning that -o flags ;; from sub-commands might be parsed. -- cgit v1.2.3