Skip to content

Commit

Permalink
Add context-switching hook
Browse files Browse the repository at this point in the history
Closes #193.
  • Loading branch information
jinnovation committed Apr 28, 2024
1 parent 8f3c451 commit ee667b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/how-tos/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ Kele commands involving Kubernetes [contexts] center around the `s-k c` prefix (
Most context-related Kele functionality can also be done via [Embark] on any
completion candidate in any context-related Kele command.

!!! tip

If you have functions that need to run after switching to a new context in
order to use it, `kele-after-context-switch-hook` is available to use. This
can be useful for, say, re-authenticating with the new context before
interacting with it.

### Managing proxy servers

Kele allows for starting and stopping [HTTP
Expand Down
6 changes: 5 additions & 1 deletion kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pods."
:type 'integer
:group 'kele)

(defvar kele-after-context-switch-hook nil
"Normal hook run after switching to a new context.")

(defvar kele--discovery-last-refresh-time nil
"Timestamp of last successful poll of the discovery cache.")

Expand Down Expand Up @@ -741,7 +744,8 @@ node `(elisp)Programmed Completion'."
'warning)))
(interactive (list (completing-read "Context: " #'kele--contexts-complete)))
(kele--with-progress (format "Switching to use context `%s'..." context)
(kele-kubectl-do "config" "use-context" context)))
(kele-kubectl-do "config" "use-context" context)
(run-hooks 'kele-after-context-switch-hook)))

;; TODO(#176): Update `kele--namespace-cache'
(transient-define-suffix kele-context-rename (old-name new-name)
Expand Down

0 comments on commit ee667b6

Please sign in to comment.