From 53dae7f8be8eed5f2a2608fb2aa6332e7fddaa60 Mon Sep 17 00:00:00 2001 From: "Christopher R. Nelson" Date: Sun, 18 Jun 2023 20:51:45 -0400 Subject: feat: improve usage of config files --- scripts/rh-client.scm.in | 62 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) mode change 100644 => 100755 scripts/rh-client.scm.in (limited to 'scripts') diff --git a/scripts/rh-client.scm.in b/scripts/rh-client.scm.in old mode 100644 new mode 100755 index 0fddb63..d81acc4 --- a/scripts/rh-client.scm.in +++ b/scripts/rh-client.scm.in @@ -1,5 +1,65 @@ -(use-modules (reading-heap client) +#!/usr/bin/env guile +!# +(define-module (reading-heap client)) + +(use-modules (simple-zmq) (config) (config api) + (config parser sexp) (config licenses)) +(define config + (configuration + (name 'rh-client) + (synopsis "client for reading-heap") + (keywords + (list + (setting + (name 'service-socket) + (synopsis "socket for communication with the service") + (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR") + "/tmp") + "/reading-heap.sock"))) + (switch + (name 'write) + (synopsis "write the default config") + (default #f) + (test boolean?) + (character #f)) + (switch + (name 'next) + (synopsis "get the next media to consume") + (default #f) + (test boolean?) + (character #t)) + )) + (directory (list (in-home ".reading-heap/") + (path (given + (string-append (or (getenv "XDG_CONFIG_HOME") + (string-append (getenv "HOME") + "/.config")) + "/reading-heap/")) + (eager? #t)))) + (parser sexp-parser))) + + +(define context (zmq-create-context)) +(define client-socket (zmq-create-socket context ZMQ_REQ)) + +(define (client-setup sock) + (zmq-connect client-socket sock)) + +(define (rh-client-next) + (zmq-send client-socket "next") + (let ((msg (zmq-receive-bytevector client-socket 65335))) + (display (bv->string msg)))) + +(define (main cmd-line) + (let ((options (getopt-config-auto cmd-line config))) + (when (option-ref options 'write) + (options-write options)) + (when (option-ref options 'next) + (client-setup (option-ref options 'service-socket)) + (rh-client-next)))) + +(main (command-line)) -- cgit v1.2.3