Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
better handle prompt cancellations
Browse files Browse the repository at this point in the history
  • Loading branch information
aavshr committed Sep 15, 2023
1 parent 2e311e3 commit aeb33f3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func promptForDiscoveryData() (*shared.DiscoveryData, error) {
Validator: validateAppName,
})
if err != nil {
return nil, fmt.Errorf("problem while trying to get title from text prompt, %w", err)
return nil, err
}
discoveryData.AppName = name

Expand All @@ -203,7 +203,7 @@ func promptForDiscoveryData() (*shared.DiscoveryData, error) {
Validator: validateAppDescription,
})
if err != nil {
return nil, fmt.Errorf("problem while trying to get tagline from text prompt, %w", err)
return nil, err
}
discoveryData.Tagline = tagline

Expand All @@ -220,7 +220,7 @@ func promptForReleaseNotes() (string, error) {
},
})
if err != nil {
return "", fmt.Errorf("problem while trying to get release notes from text prompt, %w", err)
return "", err
}
return notes, nil
}
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"errors"
"github.com/deta/space/cmd/utils"
"github.com/deta/space/pkg/components"
"github.com/deta/space/pkg/components/emoji"
"github.com/deta/space/pkg/components/styles"
"os"
Expand All @@ -11,6 +13,10 @@ import (

func main() {
if err := cmd.NewSpaceCmd().Execute(); err != nil {
// user prompt cancellation is not an error
if errors.Is(err, components.ErrPromptCancelled) {
return
}
utils.StdErrLogger.Println(styles.Errorf("%s Error: %v", emoji.ErrorExclamation, err))
os.Exit(1)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/choose/choose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package choose

import (
"fmt"
"github.com/deta/space/pkg/components"

tea "github.com/charmbracelet/bubbletea"
"github.com/deta/space/pkg/components/styles"
Expand Down Expand Up @@ -117,7 +118,7 @@ func Run(prompt string, choices ...string) (string, error) {
}

if model.Cancelled {
return "", fmt.Errorf("cancelled")
return "", components.ErrPromptCancelled
}

return model.Selection(), nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/components/components.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package components

import "errors"

var (
// ErrPromptCancelled is returned when prompt is cancelled
ErrPromptCancelled = errors.New("prompt cancelled")
)
3 changes: 2 additions & 1 deletion pkg/components/confirm/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package confirm

import (
"fmt"
"github.com/deta/space/pkg/components"

tea "github.com/charmbracelet/bubbletea"
"github.com/deta/space/pkg/components/styles"
Expand Down Expand Up @@ -80,7 +81,7 @@ func Run(input string) (bool, error) {
}

if model.Cancelled {
return false, fmt.Errorf("cancelled")
return false, components.ErrPromptCancelled
}
return model.Confirm, nil
}
3 changes: 2 additions & 1 deletion pkg/components/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package text

import (
"fmt"
"github.com/deta/space/pkg/components"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -119,7 +120,7 @@ func Run(i *Input) (string, error) {
}

if model.Cancelled {
return "", fmt.Errorf("cancelled")
return "", components.ErrPromptCancelled
}

return model.Value(), nil
Expand Down

0 comments on commit aeb33f3

Please sign in to comment.