From a0e42b7946cc2d5d31cdb593e3a764ab79bb2572 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 9 May 2025 13:47:27 -0500 Subject: [PATCH] pr: add spinner to pr create --- pr/create.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pr/create.go b/pr/create.go index 9d9ec3c..0aa3b96 100644 --- a/pr/create.go +++ b/pr/create.go @@ -1,15 +1,17 @@ package pr import ( + "context" "errors" "fmt" - "io" "net/http" "net/url" "path" "strings" + "sync" "github.com/charmbracelet/huh" + "github.com/charmbracelet/huh/spinner" "github.com/spf13/cobra" "github.com/zalando/go-keyring" "tangled.sh/rockorager.dev/knit" @@ -98,6 +100,18 @@ func Create(cmd *cobra.Command, args []string) error { Path: path.Join(p, "/pulls/new"), } + ctx, stop := context.WithCancel(cmd.Context()) + defer stop() + wg := &sync.WaitGroup{} + wg.Add(1) + go func(wg *sync.WaitGroup) { + spinner.New(). + Context(ctx). + Title("Creating PR..."). + Run() + wg.Done() + }(wg) + resp, err := client.Post( u.String(), "application/x-www-form-urlencoded", @@ -112,12 +126,8 @@ func Create(cmd *cobra.Command, args []string) error { return fmt.Errorf("unexpected status code: %d", resp.StatusCode) } - b, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - fmt.Println(string(b)) + stop() + wg.Wait() return nil } -- 2.51.2