Skip to content

Commit

Permalink
feat(internal): Add method to run code before/after prompts
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc committed Jun 5, 2024
1 parent 3fe4a52 commit 8427fa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/cli/kraft/lib/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (opts *CreateOptions) Run(ctx context.Context, args []string) error {

if !config.G[config.KraftKit](ctx).NoPrompt {
if !opts.GitInit {
opts.GitInit, err = confirm.NewConfirm("Do you want to intialise library with git:")
opts.GitInit, err = confirm.NewConfirm("Do you want to intialise library with git:", func() {})
if err != nil {
return err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (opts *CreateOptions) Run(ctx context.Context, args []string) error {
}

if !opts.UpdateRefs {
opts.UpdateRefs, err = confirm.NewConfirm("Do you want to package it:")
opts.UpdateRefs, err = confirm.NewConfirm("Do you want to package it:", func() {})
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion tui/confirm/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// NewConfirm is a utility method used in a CLI context to prompt the user with
// a yes/no question.
func NewConfirm(question string) (bool, error) {
func NewConfirm(question string, beforeAfter func()) (bool, error) {
input := confirmation.New(
tui.TextWhiteBgBlue("[?]")+" "+
question,
Expand All @@ -24,5 +24,8 @@ func NewConfirm(question string) (bool, error) {
input.KeyMap.SelectYes = append(input.KeyMap.SelectYes, "+")
input.KeyMap.SelectNo = append(input.KeyMap.SelectNo, "-")

beforeAfter()
defer beforeAfter()

return input.RunPrompt()
}

0 comments on commit 8427fa9

Please sign in to comment.