blob: 9b3b9c23429666476af755b12bd76980a8c9fad8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
;;; Copyright © 2026 Frederick M Muriithi <fredmanglis@gmail.com>
(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>
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>
(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 <codex> 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)))
|