From: Eshel Yaron Date: Wed, 14 Aug 2024 19:10:33 +0000 (+0200) Subject: Teach 'kubed-patch' about buffer-local contexts X-Git-Tag: v0.3.2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5b2f47142a38fde1507540429aa6e3e47cd24abe;p=kubed.git Teach 'kubed-patch' about buffer-local contexts * kubed.el (kubed-patch): Use buffer-local context and handle prefix arg. * kubed-transient.el (kubed-transient-patch): Add "--context=" infix argument. --- diff --git a/kubed-transient.el b/kubed-transient.el index 2b03ffb..c63819a 100644 --- a/kubed-transient.el +++ b/kubed-transient.el @@ -189,6 +189,8 @@ ["Options" ("-n" "Namespace" "--namespace=" :prompt "Namespace" :reader kubed-transient-read-namespace) + ("-C" "Context" "--context=" + :prompt "Context" :reader kubed-transient-read-context) ("-t" "Patch type" "--type=" :prompt "Patch type: " :choices ("strategic" "merge" "json"))]] diff --git a/kubed.el b/kubed.el index 2dcbba6..02aa2e2 100644 --- a/kubed.el +++ b/kubed.el @@ -2908,11 +2908,12 @@ Optional argument NAMESPACE is the namespace in which to look for NAME. STRATEGY is the patch type to use, one of \"json\", \"merge\" and \"strategic\", defaulting to \"strategic\". -Interactively, prompt for TYPE, NAME and PATCH." +Interactively, prompt for TYPE, NAME and PATCH. With a prefix argument, +prompt for NAMESPACE too. With a double prefix argument, also prompt +for CONTEXT." (interactive - (let ((type (kubed-read-resource-type "Resource type to patch")) - (context nil) (namespace nil) (strategy nil)) - (dolist (arg (kubed-transient-args 'kubed-transient-apply)) + (let ((type nil) (context nil) (namespace nil) (strategy nil)) + (dolist (arg (kubed-transient-args 'kubed-transient-patch)) (cond ((string-match "--namespace=\\(.+\\)" arg) (setq namespace (match-string 1 arg))) @@ -2920,8 +2921,20 @@ Interactively, prompt for TYPE, NAME and PATCH." (setq context (match-string 1 arg))) ((string-match "--type=\\(.+\\)" arg) (setq strategy (match-string 1 arg))))) - (list type - (kubed-read-resource-name type "Resource to patch") + (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)))) + (list (kubed-read-resource-type "Resource type to patch" nil context) + (kubed-read-resource-name type "Resource to patch" nil nil context namespace) (kubed-read-patch) context namespace strategy))) (message "Applying patch to `%s'..." name) (unless (zerop