From: Eshel Yaron Date: Wed, 21 Aug 2024 09:09:57 +0000 (+0200) Subject: (kubed-list-transient): Add type-specific suffixes X-Git-Tag: v0.4.0~9 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fa81f41a97e956bb51f1fca897073e4747aea29c;p=kubed.git (kubed-list-transient): Add type-specific suffixes * kubed-transient.el (kubed-list-transient): Tweak layout; add type-specific suffixes. * kubed.el (kubed-list-transient-extra-suffixes): New var. (kubed-define-resource): Set it to value of new keyword arg ':suffixes'. (pod, deployment): Specify new keyword arg ':suffixes'. --- diff --git a/kubed-transient.el b/kubed-transient.el index 968d63c..9b50167 100644 --- a/kubed-transient.el +++ b/kubed-transient.el @@ -499,28 +499,33 @@ defaults to \"RESOURCEs\"." ("RET" "Select" kubed-list-select-resource) ("C-o" "Display" kubed-list-display-resource :transient t) ("e" "Edit" kubed-list-edit :transient t) - ("w" "Copy name" kubed-list-copy-as-kill :transient t)] + ("w" "Copy name" kubed-list-copy-as-kill :transient t) + ("!" "Command line" kubed-list-kubectl-command :transient t)] ["Delete" ("D" "Delete" kubed-list-delete :transient t) ("d" "Mark" kubed-list-mark-for-deletion :transient t) ("u" "Unmark" kubed-list-unmark :transient t) - ("x" "Delete marked" kubed-list-delete-marked :transient t)] - ["Other" - ("!" "Command line" kubed-list-kubectl-command :transient t) - ("+" "Create" kubed-list-create :transient t) - ("/" "Filter" kubed-list-set-filter :transient t) - ("g" "Update" kubed-list-update :transient t)] + ("x" "Delete marked" kubed-list-delete-marked :transient t) + ("+" "Create" kubed-list-create :transient t)] ["Table" ("|" "Fit column" kubed-list-fit-column-width-to-content :transient t) ("}" "Widen column" tabulated-list-widen-current-column :transient t) ("{" "Narrow column" tabulated-list-narrow-current-column :transient t) - ("S" "Sort" tabulated-list-sort :transient t)] + ("S" "Sort" tabulated-list-sort :transient t) + ("/" "Filter" kubed-list-set-filter :transient t)] ["Movement" :pad-keys t ("n" "Next line" next-line :transient t) ("p" "Previous line" previous-line :transient t) ("TAB" "Next column" kubed-list-next-column :transient t) - ("S-TAB" "Previous column" kubed-list-previous-column :transient t)]]) + ("S-TAB" "Previous column" kubed-list-previous-column :transient t) + ("g" "Update" kubed-list-update :transient t)]] + ["Type Specific" + :class transient-columns + :setup-children + (lambda (_) + (transient-parse-suffixes 'kubed-list-transient + kubed-list-transient-extra-suffixes))]) (provide 'kubed-transient) ;;; kubed-transient.el ends here diff --git a/kubed.el b/kubed.el index 1c2bee0..0140729 100644 --- a/kubed.el +++ b/kubed.el @@ -499,6 +499,9 @@ If FILTER is omitted or nil, it defaults to `kubed-list-filter'." (defvar-local kubed-list-context nil) (defvar-local kubed-list-namespace nil) +(defvar-local kubed-list-transient-extra-suffixes nil + "List of transient suffixes for the type of resources in current buffer.") + (defun kubed-list-go-to-line (id) "Go to beginning of table line with ID." (let ((pos nil)) @@ -1212,7 +1215,7 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are: - `:create (ARGLIST DOCSTRING INTERACTIVE BODY...)': specialize the resource creation command, `kubed-create-RESOURCE'. ARGLIST, DOCSTRING, INTERACTIVE and BODY have the same meaning as in `defun'. -- `:prefix ((KEY LABEL DEFINITION) ...)': additional keybinding for the +- `:prefix ((KEY LABEL DEFINITION)...)': additional keybinding for the prefix keymap `kubed-RESOURCE-prefix-map' and the `kubed-RESOURCE-menu-map' menu. Each element (KEY LABEL DEFINITION) says to bind KEY to DEFINITION in `kubed-RESOURCE-menu-map', and to @@ -1220,7 +1223,9 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are: - `:plural PLURAL': specify plural form of RESOURCE, as a symbol. If you omit this keyword argument, the plural form defaults to RESOURCE followed by \"s\". -- `:logs t': generate `kubed-logs-for-RESOURCE' command." +- `:logs t': generate `kubed-logs-for-RESOURCE' command. +- `:suffixes (SUFFIX...)': add type-specific transient suffixes to + `kubed-list-transient'." (declare (indent 2)) (let ((plrl-var (intern (format "%Ss" resource))) (read-fun (intern (format "kubed-read-%S" resource))) @@ -1234,7 +1239,7 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are: (namespaced t) (logs nil) (keyword nil) frmt-var buff-fun list-cmd expl-cmd dlt-name mod-name - ctxt-fun crt-spec prf-keys hist-var) + ctxt-fun crt-spec prf-keys hist-var trs-cols) ;; Process keyword arguments. (while (keywordp (car commands)) @@ -1245,6 +1250,7 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are: ((eq keyword :create) (setq crt-spec (pop commands))) ((eq keyword :prefix) (setq prf-keys (pop commands))) ((eq keyword :plural) (setq plrl-var (pop commands))) + ((eq keyword :suffixes) (setq trs-cols (pop commands))) ;; FIXME: Add error for unknown keywords. (t (pop commands)))) @@ -1571,6 +1577,8 @@ a prefix argument \\[universal-argument], prompt for CONTEXT too." (setq kubed-list-filter-history-variable ',(intern (format "kubed-%S-filter-history" plrl-var)) kubed-list-type ,(symbol-name plrl-var) + ,@(when trs-cols + `(kubed-list-transient-extra-suffixes ',trs-cols)) tabulated-list-padding 2 tabulated-list-format (apply #'vector (cons kubed-name-column ,frmt-var))) (add-hook 'context-menu-functions #',ctxt-fun nil t) @@ -1690,6 +1698,13 @@ Interactively, use the current context. With a prefix argument :prefix (("A" "Attach" kubed-attach) ("X" "Execute" kubed-exec) ("F" "Forward Port" kubed-forward-port-to-pod)) + :suffixes ([("L" "Logs" kubed-transient-logs-for-pod) + ("X" "Exec" kubed-pods-exec) + ("a" "Attach" kubed-pods-attach)] + [("C-d" "Dired" kubed-pods-dired) + ("s" "Shell" kubed-pods-shell) + ("F" "Forward port" kubed-pods-forward-port) + :pad-keys t]) (dired "C-d" "Start Dired in" ;; Explicit namespace in Kuberenetes remote file names ;; introduced in Emacs 31. See Bug#59797. @@ -2050,6 +2065,9 @@ NAMESPACE too. With a double prefix argument, also prompt for CONTEXT." :prefix (("R" "Restart" kubed-restart-deployment) ("W" "Watch" kubed-watch-deployment-status)) :logs t + :suffixes ([("L" "Logs" kubed-transient-logs-for-deployment) + ("W" "Watch" kubed-deployments-watch) + ("R" "Restart" kubed-deployments-restart)]) :create ((name images &optional context namespace replicas port command) "Deploy IMAGES to Kubernetes in deployment with name NAME.