Accept feeds over stdin

E.g., `cat feed.xml | feedsnake -- -` or `cat feed.xml | feedsnake`
This commit is contained in:
Jaidyn Ann 2022-12-26 15:20:32 -06:00
parent 89612f3d54
commit c2e25f7800

View File

@ -360,7 +360,7 @@
(import scheme (import scheme
(chicken base) (chicken file) (chicken file posix) (chicken io) (chicken base) (chicken file) (chicken file posix) (chicken io)
(chicken process-context) (chicken process-context posix) (chicken port) (chicken process-context) (chicken process-context posix)
srfi-1 srfi-19 srfi-1 srfi-19
feedsnake feedsnake-helpers feedsnake feedsnake-helpers
getopt-long) getopt-long)
@ -382,7 +382,7 @@
(single-char #\d) (single-char #\d)
(value (required DIR))) (value (required DIR)))
(output (output
"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 (since
@ -398,7 +398,6 @@
;; The `main` procedure that should be called to run feedsnake-unix for use as script. ;; The `main` procedure that should be called to run feedsnake-unix for use as script.
;; 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)]) [free-args (alist-ref '@ args)])
@ -406,8 +405,11 @@
(help) (help)
(let ([feeds (let ([feeds
(map (lambda (file) (map (lambda (file)
(list file (let ([feed
(call-with-input-file file read-feed))) (if (string=? file "-")
(call-with-input-string (read-string) read-feed)
(call-with-input-file file read-feed))])
(list file feed)))
free-args)]) free-args)])
(map (lambda (feed-pair) (map (lambda (feed-pair)
(process-feed args feed-pair)) (process-feed args feed-pair))