Skip to content

Commit

Permalink
Run post-context-switch functions with new context name (#251)
Browse files Browse the repository at this point in the history
Closes #250.
  • Loading branch information
jinnovation authored Jan 12, 2025
1 parent 773cdd7 commit c054b40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/how-tos/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Kele commands involving Kubernetes [contexts] center around the `s-k c` prefix (
!!! 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
order to use it, `kele-context-after-switch-functions` is available to use. This
can be useful for, say, re-authenticating with the new context before
interacting with it.

Expand Down
7 changes: 7 additions & 0 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ versioning][semver].
created using `kele-port-forward`
- Rename `kele-proxy` to `kele-ports`

### Changed

- Renamed `kele-after-context-switch-hook` to
`kele-context-after-switch-functions`. Each member of this variable is now
expected to take the new context name as the sole argument (previously, they
took no arguments).

## 0.6.0

### Added
Expand Down
10 changes: 7 additions & 3 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ pods."
:type 'integer
:group 'kele)

(defvar kele-after-context-switch-hook nil
"Normal hook run after switching to a new context.")
(defvar kele-context-after-switch-functions nil
"Functions to run after switching to a new context.
Each function is expected to take a single string argument
representing the name of the new context.")

(defvar kele--discovery-last-refresh-time nil
"Timestamp of last successful poll of the discovery cache.")
Expand Down Expand Up @@ -884,7 +887,8 @@ node `(elisp)Programmed Completion'."
(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)
(run-hooks 'kele-after-context-switch-hook)))
(run-hooks 'kele-after-context-switch-hook)
(run-hook-with-args 'kele-context-after-switch-functions context)))

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

0 comments on commit c054b40

Please sign in to comment.