Skip to content

Commit

Permalink
Support specifying YAML mode to use w/ auto-detect and disable (#201)
Browse files Browse the repository at this point in the history
Closes #96.
Closes #200.
  • Loading branch information
jinnovation authored Jun 3, 2024
1 parent 294a75a commit 96467b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ versioning][semver].
populates based on the resource kind you selected.
- Added ability to `delete` individual resources via `kele-resource` and
`kele-list`
- Added variable for selecting which YAML major mode function to use for YAML
highlighting in resource buffers

### Fixed

Expand All @@ -26,6 +28,8 @@ versioning][semver].
show no kinds present in cluster
- Fixed a bug in `kele-resource` where the improper singular/plural form of the
resource name is used, e.g. "Get a single pods" instead of "Get a single pod"
- Fixed a bug where keybinding explanation "blurbs" in `kele-get` buffers don't
properly show the keybinding in clickable form

### Changed

Expand Down
19 changes: 13 additions & 6 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ pods."
:type 'boolean
:group 'kele)

(defcustom kele-yaml-highlighting-mode
(cond ((featurep 'yaml-mode) 'yaml-mode)
((featurep 'yaml-ts-mode) 'yaml-ts-mode))
"Which major mode to use for YAML highlighting.
Set to nil to disable YAML highlighting."
:type '(choice nil symbol))

(define-error 'kele-cache-lookup-error
"Kele failed to find the requested resource in the cache.")
(define-error 'kele-request-error "Kele failed in querying the Kubernetes API")
Expand Down Expand Up @@ -1198,7 +1206,7 @@ context and namespace in its name."
(cl-assert (and object (if (kele--resource-container-p object)
(kele--resource-container-resource object)
t)))
(let* ((buf-name (concat " *kele: "
(let* ((buf-name (concat "*kele: "
(if (kele--resource-container-p object)
(concat
(kele--resource-container-context object)
Expand Down Expand Up @@ -1227,9 +1235,6 @@ context and namespace in its name."
(whitespace-cleanup)
(goto-char (point-min)))

(if (featurep 'yaml-mode) (yaml-mode)
(message "[kele] For syntax highlighting, install `yaml-mode'."))

(when (kele--resource-container-p object)
(setq-local kele--current-resource-buffer-context
(kele--resource-buffer-context-create
Expand All @@ -1240,7 +1245,9 @@ context and namespace in its name."
:namespace (kele--resource-container-namespace object)))
(put 'kele--current-resource-buffer-context 'permanent-local t))

(kele-get-mode 1))
(kele-get-mode 1)
(when kele-yaml-highlighting-mode
(funcall kele-yaml-highlighting-mode)))
(select-window (display-buffer buf))))

(defun kele--prune (alist &rest keys)
Expand Down Expand Up @@ -1670,7 +1677,7 @@ is not namespaced, returns an error."
(or group
(propertize "N/A" 'face 'kele-disabled-face))
version))))))))))
(let ((buf (get-buffer-create (format " *kele: %s/%s [%s(%s)]*"
(let ((buf (get-buffer-create (format "*kele: %s/%s [%s(%s)]*"
group-version
kind
context
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test-integration.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
(call-interactively #'kele-get))
(expect (-map #'buffer-name (buffer-list))
:to-contain
" *kele: kind-kele-test-cluster0(kube-system): Deployment/coredns*")))
"*kele: kind-kele-test-cluster0(kube-system): Deployment/coredns*")))

(describe "kele-list"
(before-all
Expand All @@ -94,8 +94,8 @@
(kele-list "apps/v1" "deployments" "kind-kele-test-cluster0" "kube-system")
(expect (-map #'buffer-name (buffer-list))
:to-contain
" *kele: apps/v1/deployments [kind-kele-test-cluster0(kube-system)]*")
(let* ((buf (get-buffer " *kele: apps/v1/deployments [kind-kele-test-cluster0(kube-system)]*"))
"*kele: apps/v1/deployments [kind-kele-test-cluster0(kube-system)]*")
(let* ((buf (get-buffer "*kele: apps/v1/deployments [kind-kele-test-cluster0(kube-system)]*"))
(entries (funcall (buffer-local-value 'tabulated-list-entries buf))))
(expect (length entries) :to-equal 1)
(expect (caar entries) :to-equal (kele--list-entry-id-create
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test-kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,18 @@ metadata:
:resource fake-obj
:context "fake-context"
:namespace "fake-namespace"))
(expect (-map #'buffer-name (buffer-list)) :to-contain " *kele: fake-context(fake-namespace): FakeKind/fake-name*"))
(expect (-map #'buffer-name (buffer-list)) :to-contain "*kele: fake-context(fake-namespace): FakeKind/fake-name*"))
(describe "when the resource is not namespaced"
(it "buffer name only shows context, kind, and name"
(kele--render-object (kele--resource-container-create
:resource fake-obj
:context "fake-context"
:namespace nil))
(expect (-map #'buffer-name (buffer-list)) :to-contain " *kele: fake-context: FakeKind/fake-name*"))))
(expect (-map #'buffer-name (buffer-list)) :to-contain "*kele: fake-context: FakeKind/fake-name*"))))
(describe "when input is regular alist"
(it "buffer name only has kind and name"
(kele--render-object fake-obj)
(expect (-map #'buffer-name (buffer-list)) :to-contain " *kele: FakeKind/fake-name*")))))
(expect (-map #'buffer-name (buffer-list)) :to-contain "*kele: FakeKind/fake-name*")))))

(describe "kele--get-resource"
(before-each
Expand Down

0 comments on commit 96467b8

Please sign in to comment.