1
0
Disbranĉigi 0

Add --output option; default stdout

This commit is contained in:
Jaidyn Ann 2023-01-15 21:31:01 -06:00
parent 091e518828
commit b08db1b457

View File

@ -26,8 +26,14 @@
;; Write a to-be-JSON alist to the appropriate output
(define (chatd-json-write conn alist)
(json-write alist)
(print "\n"))
(let* ([configured-output? (hash-table-exists? conn 'output)]
[output (if configured-output?
(open-output-file (hash-table-ref conn 'output))
(open-output-file* fileno/stdout))])
(json-write alist output)
(write-string "\n" #f output)
(if configured-output?
(close-output-port output))))
;; Return a user-info in chatd-friendly alist-format, by its alist
@ -174,13 +180,18 @@
(value (required PASSWORD)))
(name
"Set the realname of your connection."
(value (required NAME)))))
(value (required NAME)))
(output
"Output path for messages. Defaults to standard output."
(single-char #\o)
(value (required PATH)))))
;; Prints cli usage to stderr.
(define (help)
(write-string *help-msg* #f (open-output-file* fileno/stderr))
(write-string (usage *opts*) #f (open-output-file* fileno/stderr)))
(write-string (usage *opts*) #f (open-output-file* fileno/stderr))
(exit 1))
;; The `main` procedure that should be called to run feedsnake-unix for use as script.
@ -188,7 +199,8 @@
(let* ([args (getopt-long (command-line-arguments) *opts*)]
[free-args (alist-ref '@ args)])
(if (or (null? free-args) (alist-ref 'help args))
(help)
(help))
(let*
([username (or (alist-ref 'username args)
(current-effective-user-name))]
@ -199,12 +211,21 @@
[server (last free-args)]
[hostname (first (string-split server ":"))]
[port (or (string->number (last (string-split server ":")))
6697)])
(if server
(irc:loop (irc:connect server port username nickname password fullname)
6697)]
[output (alist-ref 'output args)]
[connection (if server
(irc:connect server port username nickname password fullname)
#f)])
(unless connection
(help))
(if output
(hash-table-set! connection 'output output))
(irc:loop connection
on-command
on-reply)
(help))))))
on-reply))))
(main)