Add --output option; default stdout
This commit is contained in:
parent
091e518828
commit
b08db1b457
|
@ -26,8 +26,14 @@
|
||||||
|
|
||||||
;; Write a to-be-JSON alist to the appropriate output
|
;; Write a to-be-JSON alist to the appropriate output
|
||||||
(define (chatd-json-write conn alist)
|
(define (chatd-json-write conn alist)
|
||||||
(json-write alist)
|
(let* ([configured-output? (hash-table-exists? conn 'output)]
|
||||||
(print "\n"))
|
[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
|
;; Return a user-info in chatd-friendly alist-format, by its alist
|
||||||
|
@ -174,13 +180,18 @@
|
||||||
(value (required PASSWORD)))
|
(value (required PASSWORD)))
|
||||||
(name
|
(name
|
||||||
"Set the realname of your connection."
|
"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.
|
;; Prints cli usage to stderr.
|
||||||
(define (help)
|
(define (help)
|
||||||
(write-string *help-msg* #f (open-output-file* fileno/stderr))
|
(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.
|
;; The `main` procedure that should be called to run feedsnake-unix for use as script.
|
||||||
|
@ -188,23 +199,33 @@
|
||||||
(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)])
|
||||||
(if (or (null? free-args) (alist-ref 'help args))
|
(if (or (null? free-args) (alist-ref 'help args))
|
||||||
(help)
|
(help))
|
||||||
(let*
|
|
||||||
([username (or (alist-ref 'username args)
|
(let*
|
||||||
(current-effective-user-name))]
|
([username (or (alist-ref 'username args)
|
||||||
[password (alist-ref 'password args)]
|
(current-effective-user-name))]
|
||||||
[nickname (or (alist-ref 'nickname args)
|
[password (alist-ref 'password args)]
|
||||||
(current-effective-user-name))]
|
[nickname (or (alist-ref 'nickname args)
|
||||||
[fullname (alist-ref 'name args)]
|
(current-effective-user-name))]
|
||||||
[server (last free-args)]
|
[fullname (alist-ref 'name args)]
|
||||||
[hostname (first (string-split server ":"))]
|
[server (last free-args)]
|
||||||
[port (or (string->number (last (string-split server ":")))
|
[hostname (first (string-split server ":"))]
|
||||||
6697)])
|
[port (or (string->number (last (string-split server ":")))
|
||||||
(if server
|
6697)]
|
||||||
(irc:loop (irc:connect server port username nickname password fullname)
|
[output (alist-ref 'output args)]
|
||||||
on-command
|
[connection (if server
|
||||||
on-reply)
|
(irc:connect server port username nickname password fullname)
|
||||||
(help))))))
|
#f)])
|
||||||
|
|
||||||
|
(unless connection
|
||||||
|
(help))
|
||||||
|
|
||||||
|
(if output
|
||||||
|
(hash-table-set! connection 'output output))
|
||||||
|
|
||||||
|
(irc:loop connection
|
||||||
|
on-command
|
||||||
|
on-reply))))
|
||||||
|
|
||||||
|
|
||||||
(main)
|
(main)
|
||||||
|
|
Reference in New Issue