;;; Copyright © 2026 Frederick M Muriithi (define-module (web config) #:use-module (srfi srfi-9 gnu) #:use-module (config) #:use-module (config api) #:use-module (config parser sexp) #:export ( gn-guile-config-port gn-guile-config-gn-docs-remote-url gn-guile-config-gn-docs-local-checkout gn-guile-config-gn-docs-working-branch parse-cli-options cli-options->gn-guile-config)) (define-immutable-record-type (gn-guile-config port gn-docs-remote-url gn-docs-local-checkout gn-docs-working-branch) gn-guile-config? (port gn-guile-config-port) (gn-docs-remote-url gn-guile-config-gn-docs-remote-url) (gn-docs-local-checkout gn-guile-config-gn-docs-local-checkout) (gn-docs-working-branch gn-guile-config-gn-docs-working-branch)) (define string->exact (compose inexact->exact string->number)) (define (user-port? parsed) (and (positive? parsed) (>= parsed 1024) (<= parsed 49151))) (define (parse-cli-options cmd-line) "Read configuration values from files and command-line options and convert them to appropriate data types." (let ((config (configuration (name 'gn-guile) (synopsis "gn-guile web service: provide services to main Genenetwork service.") (description "gn-guile web service is a small service, written in GNU Guile, that provides some functionality to the main Genenetwork service in the background. This is not meant for direct user interaction.") (keywords (list (switch (name 'write) (default #f) (test boolean?) (character #f) (synopsis "Write the settings to configuration file(s)") (description "When this option is present, the configuration values, provided as command line option, will be written to the file path(s) that has/have been specified.")) (setting (name 'port) (default 8091) (test user-port?) (handler string->exact) (character #\p) (synopsis "Port number that the service will listen on")) (setting (name 'gn-docs-remote-url) (default "git@git.genenetwork.org:/home/git/public/gn-docs") (test string?) (character #\r) (synopsis "Remote URI for gn-docs repository")) (setting (name 'gn-docs-local-checkout) (default (string-append (dirname (getcwd)) "/gn-guile-files/gn-docs")) (test file-exists?) (character #\c) (synopsis "Path where gn-docs is checked out")) (setting (name 'gn-docs-working-branch) (default "non-existent") (test string?) (character #\b) (synopsis "Branch to push/pull from")))) (parser sexp-parser) (directory (list (in-home ".config/gn-guile/") (in-cwd ".config/")))))) (getopt-config-auto cmd-line config))) (define (cli-options->gn-guile-config cli-options) "Extract specific values from guile-config's object into gn-guile's custom configuration object." (gn-guile-config (option-ref cli-options 'port) (option-ref cli-options 'gn-docs-remote-url) (option-ref cli-options 'gn-docs-local-checkout) (option-ref cli-options 'gn-docs-working-branch)))