feat: add pre and post hook support when entering a kubert ctx shell#34
Merged
feat: add pre and post hook support when entering a kubert ctx shell#34
kubert ctx shell#34Conversation
Signed-off-by: Igor de Beijer <71566757+idebeijer@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds pre and post hook support for the kubert ctx shell command, allowing users to execute custom shell commands before entering and after exiting a Kubernetes context shell.
Key Changes:
- Added
Hooksconfiguration struct withPreShellandPostShellfields - Modified shell launching logic to execute hooks and set the
KUBERT_CONTEXTenvironment variable - Added comprehensive documentation with examples for configuring shell hooks
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/config/config.go | Adds Hooks struct with pre/post shell command fields and default configuration values |
| cmd/context.go | Implements hook execution logic, extracts shell detection to getUserShell(), and sets KUBERT_CONTEXT env var |
| README.md | Documents shell hooks feature with configuration examples and common use cases |
Comments suppressed due to low confidence (1)
cmd/context.go:261
- The
executeHook()function lacks a docstring. Consider documenting the parameters (hookCommand and hookType), what the function does, and its return behavior.
func executeHook(hookCommand, hookType string) error {
hookCmd := exec.Command(getUserShell(), "-c", hookCommand)
hookCmd.Env = os.Environ()
hookCmd.Stdout = os.Stdout
hookCmd.Stderr = os.Stderr
if err := hookCmd.Run(); err != nil {
return fmt.Errorf("%s hook failed: %w", hookType, err)
}
return nil
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds pre and post hook support for the
kubert ctxshell command, allowing users to execute custom shell commands before entering and after exiting a Kubernetes context shell.Key Changes:
Hooksconfiguration withPreShellandPostShellfieldsKUBERT_CONTEXTenvironment variable