summaryrefslogtreecommitdiff
path: root/main.scm
blob: ed980344b0cbd4ef438e887b6f1e65e1083d65cd (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
#!/usr/bin/guile \
-e main -s
!#

(add-to-load-path "/home/hugo/code/calp/module")

(use-modules
 ((hnh util) :select (path-append))
 (ice-9 getopt-long)
 ((xdg basedir) :prefix xdg-)
 ((rss-filter) :select (handle-feed)))



(define option-spec
  `((output (single-char #\o)
            (required? #f)
            (value #t)
            (description "Target directory for output files" (br)
                         "Defaults to " (i "$PWD") "."))
    (help (single-char #\h)
          (description "Print this help"))
    (config-dir (required? #f)
                (value #t)
                (description "Defaults to " (i "$XDG_CONFIG_DIR/rss-filter")))
    (quiet (value #f)
           (description "Supress info output"))))


(define (display-no-config config-dir)
  (format #t "Configuration directory [~a] doesn't exist, or is unreadable~%"
          config-dir))

(define (main args)

  (define opts (getopt-long args ((@ (hnh util options) getopt-opt) option-spec)))
  (define output-directory (option-ref opts 'output "."))

  (define config-dir
    (or ; or for lazy evaluation
      (option-ref opts 'config-dir #f)
      (path-append (xdg-config-home)
                   "rss-filter")))

  (define quiet? (option-ref opts 'quiet #f))

  (when (option-ref opts 'help #f)
    ((@ (hnh util options) print-arg-help) option-spec)
    (exit 0))

  (unless (file-exists? config-dir)
    (display-no-config config-dir)
    (exit 1))

  (add-to-load-path config-dir)

  (for-each (handle-feed output-directory quiet?) (@ (config) feeds)))