Skip to content

Instantly share code, notes, and snippets.

@DanStough
Created July 11, 2025 01:11
Show Gist options
  • Select an option

  • Save DanStough/bd95fe0b4ce411e6688bc5d89aba3539 to your computer and use it in GitHub Desktop.

Select an option

Save DanStough/bd95fe0b4ce411e6688bc5d89aba3539 to your computer and use it in GitHub Desktop.
Fang CLI Hangs on Termination
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