changelog shortlog graph tags branches files raw help

Mercurial > core / changeset: cli tweaks

changeset 625: e49442cd6010
parent 624: 97dd03beda03
child 626: cc13027df6fa
author: Richard Westhaver <ellis@rwest.io>
date: Sun, 25 Aug 2024 21:38:07 -0400
files: lisp/bin/rdb.lisp lisp/lib/cli/clap/cli.lisp lisp/lib/cli/clap/opt.lisp lisp/lib/cli/clap/pkg.lisp lisp/lib/cli/clap/proto.lisp lisp/lib/rdb/err.lisp skelfile
description: cli tweaks
     1.1--- a/lisp/bin/rdb.lisp	Sun Aug 25 20:28:57 2024 -0400
     1.2+++ b/lisp/bin/rdb.lisp	Sun Aug 25 21:38:07 2024 -0400
     1.3@@ -11,7 +11,7 @@
     1.4 (defopt rdb-version (print-version *cli*))
     1.5 (defopt rdb-log-level (when *arg* (setq *log-level* :debug)))
     1.6 (defvar *rdb*)
     1.7-(defopt rdb-target-db (setq *rdb* (create-db (or *arg* "rdb") :open nil)))
     1.8+(defopt rdb-target-db (or *arg* "rdb"))
     1.9 
    1.10 ;; (defopt rdb-config (init-rdb-user-config (parse-file-opt *arg*)))
    1.11 
    1.12@@ -21,7 +21,8 @@
    1.13   (println (rdb-name *rdb*)))
    1.14 
    1.15 (defcmd rdb-show
    1.16-  (let ((db-path (cli-opt-val (car (find-opts *cli* "db")))))
    1.17+  (let* ((db-path (cli-opt-val (car (find-opts *cli* "db"))))
    1.18+         (*rdb* (create-db db-path :open nil)))
    1.19     (if (and (null db-path) (zerop *argc*))
    1.20         (mapc (lambda (x) (println (format nil "~a ~a" (car x) (cdr x))))
    1.21               (hash-table-alist (backfill-opts (default-rdb-opts) :full t)))
    1.22@@ -90,10 +91,9 @@
    1.23 (defmain ()
    1.24   (let ((*log-level* :info))
    1.25     (with-slots (opts cmds args) *cli*
    1.26-      ;; FIXME 2024-05-07: needs to be triggered explicitly - need to support
    1.27-      ;; running global opt thunks even when no arg present - macro key
    1.28+      (do-opts (active-opts *cli* t))
    1.29       (if (active-cmds *cli*)
    1.30-          (prog2 (do-opt (car (find-opts *cli* "db")))
    1.31-              (do-cmd *cli*)
    1.32+          (let ((*rdb* (create-db (do-opt (car (find-opts *cli* "db"))))))
    1.33+            (do-cmd *cli*)
    1.34             (close-db *rdb*))
    1.35           (print-help *cli*)))))
     2.1--- a/lisp/lib/cli/clap/cli.lisp	Sun Aug 25 20:28:57 2024 -0400
     2.2+++ b/lisp/lib/cli/clap/cli.lisp	Sun Aug 25 21:38:07 2024 -0400
     2.3@@ -109,6 +109,10 @@
     2.4         (c (active-cmds cli)))
     2.5     (log:debug! :pwd (cli-cd cli) :active-opts o :cmd-args a :active-cmds c)))
     2.6 
     2.7+(defmethod do-opts ((self cli) &optional global)
     2.8+  (loop for opt across (active-opts self global)
     2.9+        do (do-opt opt)))
    2.10+
    2.11 (defmacro with-cli (slots cli &body body)
    2.12   "Like with-slots with some extra bindings.
    2.13 
     3.1--- a/lisp/lib/cli/clap/opt.lisp	Sun Aug 25 20:28:57 2024 -0400
     3.2+++ b/lisp/lib/cli/clap/opt.lisp	Sun Aug 25 21:38:07 2024 -0400
     3.3@@ -99,6 +99,11 @@
     3.4 (defmethod do-opt ((self cli-opt))
     3.5   (call-opt self (cli-opt-val self)))
     3.6 
     3.7+(defmethod do-opts ((self vector) &optional global)
     3.8+  (declare (ignore global))
     3.9+  (loop for opt across self
    3.10+        do (do-opt opt)))
    3.11+
    3.12 (defun active-global-opt-p (opt)
    3.13   "Return non-nil if OPT is active at runtime and global."
    3.14   (and (cli-opt-lock opt) (cli-opt-global opt)))
     4.1--- a/lisp/lib/cli/clap/pkg.lisp	Sun Aug 25 20:28:57 2024 -0400
     4.2+++ b/lisp/lib/cli/clap/pkg.lisp	Sun Aug 25 21:38:07 2024 -0400
     4.3@@ -26,7 +26,8 @@
     4.4    :find-cmd :find-opts :parse-args :print-help
     4.5    :print-usage :print-version :do-cmds :do-cmd
     4.6    :active-cmds :active-opts :call-opt :do-opt
     4.7-   :push-cmd :push-opt :cli-equal))
     4.8+   :push-cmd :push-opt :cli-equal
     4.9+   :do-opts))
    4.10 
    4.11 (defpackage :cli/clap/ast
    4.12   (:use :cl :std :log :dat/sxp)
     5.1--- a/lisp/lib/cli/clap/proto.lisp	Sun Aug 25 20:28:57 2024 -0400
     5.2+++ b/lisp/lib/cli/clap/proto.lisp	Sun Aug 25 21:38:07 2024 -0400
     5.3@@ -37,6 +37,8 @@
     5.4 
     5.5 (defgeneric do-opt (self))
     5.6 
     5.7+(defgeneric do-opts (self &optional global))
     5.8+
     5.9 (defgeneric call-cmd (self args opts))
    5.10 
    5.11 (defgeneric do-cmd (self)
     6.1--- a/lisp/lib/rdb/err.lisp	Sun Aug 25 20:28:57 2024 -0400
     6.2+++ b/lisp/lib/rdb/err.lisp	Sun Aug 25 21:38:07 2024 -0400
     6.3@@ -12,7 +12,7 @@
     6.4    (:auto t)
     6.5    (:documentation "Error signaled by the RDB system.")))
     6.6 
     6.7-(define-condition rocksdb-error (rdb-error)
     6.8+(define-condition rocksdb-alien-error (rdb-error)
     6.9   ((db :initarg :db :reader rdb-error-db))
    6.10   (:documentation "Error signaled by RocksDB subsystem."))
    6.11 
    6.12@@ -20,39 +20,39 @@
    6.13   (print-unreadable-object (obj stream :type t :identity t)
    6.14     (format stream "~A" (rdb-error-message obj))))
    6.15 
    6.16-(define-condition open-db-error (rocksdb-error)
    6.17+(define-condition open-db-error (rocksdb-alien-error)
    6.18   ()
    6.19   (:documentation "Error signaled while opening a database."))
    6.20 
    6.21-(define-condition open-backup-engine-error (rocksdb-error)
    6.22+(define-condition open-backup-engine-error (rocksdb-alien-error)
    6.23   ()
    6.24   (:documentation "Error signaled while opening a backup engine."))
    6.25 
    6.26-(define-condition destroy-db-error (rocksdb-error)
    6.27+(define-condition destroy-db-error (rocksdb-alien-error)
    6.28   ()
    6.29   (:documentation "Error signaled while destroying a database."))
    6.30 
    6.31-(define-condition flush-db-error (rocksdb-error)
    6.32+(define-condition flush-db-error (rocksdb-alien-error)
    6.33   ()
    6.34   (:documentation "Error signaled while flushing a database."))
    6.35 
    6.36-(define-condition ingest-db-error (rocksdb-error)
    6.37+(define-condition ingest-db-error (rocksdb-alien-error)
    6.38   ()
    6.39   (:documentation "Error signaled while ingesting a database."))
    6.40 
    6.41-(define-condition sst-writer-error (rocksdb-error)
    6.42+(define-condition sst-writer-error (rocksdb-alien-error)
    6.43   ()
    6.44   (:documentation "Error signaled while writing a SST file."))
    6.45 
    6.46-(define-condition repair-db-error (rocksdb-error)
    6.47+(define-condition repair-db-error (rocksdb-alien-error)
    6.48   ()
    6.49   (:documentation "Error signaled while repairing a database."))
    6.50 
    6.51-(define-condition destroy-backup-engine-error (rocksdb-error)
    6.52+(define-condition destroy-backup-engine-error (rocksdb-alien-error)
    6.53   ()
    6.54   (:documentation "Error signaled while destroying a backup engine."))
    6.55 
    6.56-(define-condition cf-error (rocksdb-error)
    6.57+(define-condition cf-error (rocksdb-alien-error)
    6.58   ((cf :initarg :cf :reader rdb-error-cf))
    6.59   (:documentation "Error signaled in the context of a Column Family."))
    6.60 
    6.61@@ -86,5 +86,5 @@
    6.62 additional PARAMS will be used to signal a lisp error condition."
    6.63   ;; if NULL, return nil
    6.64   (unless (null-alien errptr)
    6.65-    (apply #'signal (or errtyp 'rocksdb-error)
    6.66+    (apply #'signal (or errtyp 'rocksdb-alien-error)
    6.67            (nconc (list :message (sb-unix::strerror)) params))))
     7.1--- a/skelfile	Sun Aug 25 20:28:57 2024 -0400
     7.2+++ b/skelfile	Sun Aug 25 21:38:07 2024 -0400
     7.3@@ -56,7 +56,8 @@
     7.4               (with-sbcl (:noinform t :quit t)
     7.5                 (ql:quickload :bin/rdb)
     7.6                 (asdf:make :bin/rdb))
     7.7-              #$mv lisp/bin/rdb .stash/rdb$#))
     7.8+              #$mv lisp/bin/rdb .stash/rdb$#)
     7.9+      (:install () #$install -C -m 755 .stash/rdb /usr/local/bin/rdb$#))
    7.10  (skel (%stash)
    7.11        (:build ()
    7.12                (with-sbcl (:noinform t :quit t)