Slight refactor of in UNIX client

This commit is contained in:
Jaidyn Ann 2022-12-18 21:32:19 -06:00
parent ad3d36b0b7
commit 7ff742e99a

View File

@ -241,10 +241,9 @@
(entries-since feed last-update))) (entries-since feed last-update)))
;; List of all entries of the feed file ;; List of all entries of the feed
(define (all-entries feed-path) (define (all-entries feed)
(let ([feed (call-with-input-file feed-path read-feed)]) (car (alist-ref 'entries feed)))
(car (alist-ref 'entries feed))))
;; Atom parsing ;; Atom parsing
@ -372,6 +371,10 @@
"Output file, used for mbox output. Default is stdout." "Output file, used for mbox output. Default is stdout."
(single-char #\o) (single-char #\o)
(value (required FILE))))) (value (required FILE)))))
;; (since
;; "Output entries after the given date, in YYYY-MM-DD hh:mm:ss format."
;; (single-char #\s)
;; (value (required DATETIME)))))
;; Prints cli usage to stderr. ;; Prints cli usage to stderr.
@ -384,22 +387,33 @@
;; TODO: accept piped-in feeds ;; TODO: accept piped-in feeds
(define (main) (define (main)
(let* ([args (getopt-long (command-line-arguments) *opts*)] (let* ([args (getopt-long (command-line-arguments) *opts*)]
[output-dir (alist-ref 'outdir args)] [free-args (alist-ref '@ args)])
[output (or (alist-ref 'output args) output-dir)]
[template (if output-dir *maildir-template* *mbox-template*)])
(if (alist-ref 'help args) (if (alist-ref 'help args)
(help) (help)
(map (lambda (free-arg) (let ([feeds
(cond [(not (file-exists? free-arg)) (map (lambda (file)
#f] (list file
[output (call-with-input-file file read-feed)))
(write-entries-to-file (all-entries free-arg) template output)] free-args)])
[(not output) (map (lambda (feed-pair)
(map (lambda (entry) (process-feed args feed-pair))
(write-entry entry template feeds)))))
(open-output-file* fileno/stdout)))
(all-entries free-arg))]))
(alist-ref '@ args))))) (define (process-feed args feed-pair)
(let* ([feed (last feed-pair)]
[feed-path (first feed-pair)]
[output-dir (alist-ref 'outdir args)]
[output (or (alist-ref 'output args) output-dir)]
[template (if output-dir *maildir-template* *mbox-template*)])
(cond
[output
(write-entries-to-file (all-entries feed) template output)]
[(not output)
(map (lambda (entry)
(write-entry entry template
(open-output-file* fileno/stdout)))
(all-entries feed))])))
;; Supposed config root of the user (as per XDG, or simple ~/.config) ;; Supposed config root of the user (as per XDG, or simple ~/.config)