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*)]
[free-args (alist-ref '@ args)])
(if (alist-ref 'help args)
(help)
(let ([feeds
(map (lambda (file)
(list file
(call-with-input-file file read-feed)))
free-args)])
(map (lambda (feed-pair)
(process-feed args feed-pair))
feeds)))))
(define (process-feed args feed-pair)
(let* ([feed (last feed-pair)]
[feed-path (first feed-pair)]
[output-dir (alist-ref 'outdir args)] [output-dir (alist-ref 'outdir args)]
[output (or (alist-ref 'output args) output-dir)] [output (or (alist-ref 'output args) output-dir)]
[template (if output-dir *maildir-template* *mbox-template*)]) [template (if output-dir *maildir-template* *mbox-template*)])
(if (alist-ref 'help args) (cond
(help)
(map (lambda (free-arg)
(cond [(not (file-exists? free-arg))
#f]
[output [output
(write-entries-to-file (all-entries free-arg) template output)] (write-entries-to-file (all-entries feed) template output)]
[(not output) [(not output)
(map (lambda (entry) (map (lambda (entry)
(write-entry entry template (write-entry entry template
(open-output-file* fileno/stdout))) (open-output-file* fileno/stdout)))
(all-entries free-arg))])) (all-entries feed))])))
(alist-ref '@ args)))))
;; Supposed config root of the user (as per XDG, or simple ~/.config) ;; Supposed config root of the user (as per XDG, or simple ~/.config)