From a1c741360a824c1e2be6199c903c15a06b3fa5a1 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 14 Aug 2024 21:13:36 +0200 Subject: [PATCH] Teach 'kubed-exec' about buffer-local contexts * kubed.el (kubed-diff): Use buffer-local context and change handling of prefix argument. * kubed-transient.el (kubed-transient-exec): Add "--context=" infix argument. --- kubed-transient.el | 2 ++ kubed.el | 40 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/kubed-transient.el b/kubed-transient.el index 829eedb..0462b28 100644 --- a/kubed-transient.el +++ b/kubed-transient.el @@ -131,6 +131,8 @@ ["Options" ("-n" "Namespace" "--namespace=" :prompt "Namespace" :reader kubed-transient-read-namespace) + ("-C" "Context" "--context=" + :prompt "Context" :reader kubed-transient-read-context) ("--" "Command" "-- =" :prompt "Command: ")]] (interactive) diff --git a/kubed.el b/kubed.el index d1a40b6..a3cdb65 100644 --- a/kubed.el +++ b/kubed.el @@ -2854,13 +2854,11 @@ Non-nil STDIN says to connect local standard input to remote process. Non-nil TTY says to use a TTY for standard input. Interactively, prompt for POD; if there are multiple pod containers, -prompt for CONTAINER as well; STDIN is t unless you call this command -with \\[universal-argument] \\[universal-argument]; and TTY is t unless\ - you call this command with \\[universal-argument]." +prompt for CONTAINER as well. With a prefix argument, prompt for +NAMESPACE too. With a double prefix argument, also prompt for CONTEXT. +STDIN and TTY are t interactively." (interactive (let ((context nil) (namespace nil) (stdin t) (tty t) (command nil) (args nil)) - (when (<= 4 (prefix-numeric-value current-prefix-arg)) (setq tty nil)) - (when (<= 16 (prefix-numeric-value current-prefix-arg)) (setq stdin nil)) (dolist (arg (kubed-transient-args 'kubed-transient-exec)) (cond ((string-match "--namespace=\\(.+\\)" arg) @@ -2873,18 +2871,26 @@ with \\[universal-argument] \\[universal-argument]; and TTY is t unless\ (setq args (split-string-and-unquote (match-string 1 arg)) command (car args) args (cdr args))))) - (let* ((context (or context (kubed-current-context))) - (n (or namespace - (when current-prefix-arg - (kubed-read-namespace "Namespace" (kubed-current-namespace) nil context)))) - (p (kubed-read-pod "Attach to pod" nil nil context n)) - (c (kubed-read-container p "Container" t context n))) - (unless command - (setq args (split-string-and-unquote - (read-string "Execute command: ")) - command (car args) - args (cdr args))) - (list p command c context n stdin tty args)))) + (unless context + (setq context + (let ((cxt (kubed-local-context))) + (if (equal current-prefix-arg '(16)) + (kubed-read-context "Context" cxt) + cxt)))) + (unless namespace + (setq namespace + (let ((cur (kubed-local-namespace context))) + (if current-prefix-arg + (kubed-read-namespace "Namespace" cur nil context) + cur)))) + (unless command + (setq args (split-string-and-unquote + (read-string "Execute command: ")) + command (car args) + args (cdr args))) + (let* ((p (kubed-read-pod "Exec on pod" nil nil context namespace)) + (c (kubed-read-container p "Container" t context namespace))) + (list p command c context namespace stdin tty args)))) (pop-to-buffer (apply #'make-comint "kubed-exec" kubed-kubectl-program nil "exec" pod -- 2.39.2