From: Eshel Yaron Date: Fri, 23 Aug 2024 15:54:44 +0000 (+0200) Subject: ; Don't accept empty string as default namespace X-Git-Tag: v0.4.0~2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d9d349455bf547d247343dc20bff86daf7de29c3;p=kubed.git ; Don't accept empty string as default namespace * kubed.el (kubed-read-default-namespace-non-empty): New func. (kubed-default-context-and-namespace): Use it. --- diff --git a/kubed.el b/kubed.el index cab9eff..8e107b8 100644 --- a/kubed.el +++ b/kubed.el @@ -2323,6 +2323,15 @@ DEFAULT-BACKEND is the service to use as a backend for unhandled URLs." "Return current Kubernetes context." (car (process-lines kubed-kubectl-program "config" "current-context"))) +(defun kubed-read-default-namespace-non-empty (context) + "Prompt for a default namespace for CONTEXT, refusing empty input." + (let ((ns (kubed-read-namespace + (format "Default namespace for context `%s'" context) + nil nil context))) + (when (string-empty-p ns) + (user-error "You didn't specify a default namespace")) + ns)) + (defun kubed-default-context-and-namespace () "Return default context and namespace as a cons cell (CONTEXT . NAMESPACE)." (or kubed-default-context-and-namespace @@ -2330,9 +2339,7 @@ DEFAULT-BACKEND is the service to use as a backend for unhandled URLs." (let ((context (kubed-current-context))) (cons context (or (kubed-current-namespace context) - (kubed-read-namespace - (format "Default namespace for context `%s'" context) - nil nil context))))))) + (kubed-read-default-namespace-non-empty context))))))) (defun kubed-default-context () "Return default `kubectl' context."