Created
July 11, 2025 01:11
-
-
Save DanStough/bd95fe0b4ce411e6688bc5d89aba3539 to your computer and use it in GitHub Desktop.
Fang CLI Hangs on Termination
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
| package main | |
| import ( | |
| "context" | |
| "io" | |
| "os" | |
| "github.com/charmbracelet/fang" | |
| "github.com/spf13/cobra" | |
| ) | |
| func main() { | |
| // NewRootCMD creates the root command for the epok CLI application. | |
| rootCmd := &cobra.Command{ | |
| Use: "test", | |
| RunE: handler, | |
| } | |
| fang.Execute(context.Background(), rootCmd, | |
| fang.WithNotifySignal(os.Interrupt, os.Kill)) | |
| } | |
| func handler(cmd *cobra.Command, _ []string) error { | |
| data := make(chan string) | |
| go func() { | |
| in := cmd.InOrStdin() | |
| _, _ = io.ReadAll(in) // Will block | |
| }() | |
| ctx := cmd.Context() | |
| select { | |
| case <-ctx.Done(): | |
| return ctx.Err() | |
| case <-data: | |
| return nil | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment