(format-prompt prompt default) nil nil nil nil
'kubed-container-images-history default))
+(defun kubed-command-line-completion-table (s p a)
+ "Completion table for `kubectl' command lines.
+
+Perform completion action A on string S with predicate P."
+ (let ((start 0))
+ (while (string-match "[[:space:]]" s start)
+ (setq start (match-end 0)))
+ (cond
+ ((eq (car-safe a) 'boundaries)
+ `(boundaries ,start . ,(and (string-match "[[:space:]]" (cdr a))
+ (match-beginning 0))))
+ ((eq a 'metadata)
+ `(metadata
+ (category . kubed-command-line)
+ (affixation-function
+ . ,(lambda (cands)
+ (let ((max (seq-max
+ (cons 0 (mapcar #'string-width cands)))))
+ (mapcar
+ (lambda (cand)
+ (list
+ cand ""
+ (if-let
+ ((desc (get-text-property
+ 0 'kubed-command-line-argument-description
+ cand)))
+ (concat
+ (make-string (1+ (- max (string-width cand))) ?\s)
+ (propertize desc 'face 'completions-annotations))
+ "")))
+ cands))))))
+ (t (let ((table
+ (let* ((lines
+ (apply #'process-lines-ignore-status
+ kubed-kubectl-executable "__complete"
+ (let ((args (cdr (split-string-and-unquote s))))
+ (if (string-suffix-p " " s)
+ (nconc args '(""))
+ args))))
+ (code nil)
+ (comps (seq-take-while
+ (lambda (line)
+ (not (and (string-match "^:\\([0-9]+\\)$" line)
+ (setq code (string-to-number
+ (match-string 1 line))))))
+ lines)))
+ (when (and code (zerop (logand #b1001 code)))
+ (mapcar
+ (lambda (comp)
+ (pcase (split-string comp "\t" t)
+ (`(,c ,a . ,_)
+ (propertize c 'kubed-command-line-argument-description
+ (car (split-string a "\\." t))))
+ (`(,c . ,_) c)))
+ comps)))))
+ (if a (complete-with-action a table (substring s start) p)
+ (let ((comp (complete-with-action a table (substring s start) p)))
+ (if (stringp comp) (concat (substring s 0 start) comp) comp))))))))
+
+(defvar kubed-kubectl-command-history nil
+ "Minibuffer history for `kubed-kubectl-command'.")
+
+;;;###autoload
+(defun kubed-kubectl-command (command)
+ "Execute `kubectl' COMMAND.
+
+This function calls `shell-command' (which see) to do the work.
+
+Interactively, prompt for COMMAND with completion for `kubectl' arguments."
+ (interactive
+ (list (completing-read "Command: " #'kubed-command-line-completion-table
+ nil nil "kubectl " 'kubed-kubectl-command-history)))
+ (shell-command command))
+
;;;###autoload (autoload 'kubed-prefix-map "kubed" nil t 'keymap)
(defvar-keymap kubed-prefix-map
:doc "Prefix keymap for Kubed commands."
"d" 'kubed-deployment-prefix-map
"C" #'kubed-use-context
"A" #'kubed-all-namespaces-mode
- "+" #'kubed-create)
+ "+" #'kubed-create
+ "!" #'kubed-kubectl-command)
(provide 'kubed)
;;; kubed.el ends here