Created
July 11, 2025 01:11
-
-
Save DanStough/bd95fe0b4ce411e6688bc5d89aba3539 to your computer and use it in GitHub Desktop.
Revisions
-
DanStough created this gist
Jul 11, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ 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 } }