Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run post-context-switch functions with new context name #251

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading