]> git.eshelyaron.com Git - emacs.git/commitdiff
kubed.el: Correctly handle spaces in resource properties
authorEshel Yaron <me@eshelyaron.com>
Fri, 26 Jul 2024 10:22:27 +0000 (12:22 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 26 Jul 2024 10:22:27 +0000 (12:22 +0200)
lisp/net/kubed.el

index 84a16225dca48fea7420773d7cebd851f31e0f23..3eccdf39f69ece7fa2b0369f6ac36b60cad11584 100644 (file)
@@ -298,7 +298,6 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are:
                           ,@(when namespaced
                               `((concat "--all-namespaces="
                                         (if kubed-all-namespaces-mode "true" "false"))))
-                          "--no-headers=true"
                           (format "--output=custom-columns=%s"
                                   (string-join
                                    (cons "NAME:.metadata.name"
@@ -320,16 +319,30 @@ Other keyword arguments that go between PROPERTIES and COMMANDS are:
                 :sentinel (lambda (_proc status)
                             (cond
                              ((string= status "finished\n")
-                              (let (new)
+                              (let (new offsets eol)
                                 (with-current-buffer ,out-name
                                   (goto-char (point-min))
+                                  (setq eol (pos-eol))
+                                  (while (re-search-forward "[^ ]+" eol t)
+                                    (push (1- (match-beginning 0)) offsets))
+                                  (setq offsets (nreverse offsets))
+                                  (forward-char 1)
                                   (while (not (eobp))
-                                    (let ((line (buffer-substring
-                                                 (point)
-                                                 (progn
-                                                   (forward-line 1)
-                                                   (1- (point))))))
-                                      (push (split-string line " " t) new))))
+                                    (let ((cols nil)
+                                          (beg (car offsets))
+                                          (ends (cdr offsets)))
+                                      (dolist (end ends)
+                                        (push (string-trim (buffer-substring
+                                                            (+ (point) beg)
+                                                            (+ (point) end)))
+                                              cols)
+                                        (setq beg end))
+                                      (push (string-trim (buffer-substring
+                                                          (+ (point) beg)
+                                                          (pos-eol)))
+                                            cols)
+                                      (push (nreverse cols) new))
+                                    (forward-line 1)))
                                 (setq ,list-var new
                                       ,proc-var nil)
                                 (run-hooks ',hook-var)