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 Jul 2, 2024
1 parent 4fb0005 commit 9cd123f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/cli/kraft/build/builder_kraftfile_unikraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (build *builderKraftfileUnikraft) Build(ctx context.Context, opts *BuildOpt
configure := true

if opts.project.IsConfigured(*opts.Target) {
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:")
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:", func() {})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/kraft/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (opts *FetchOptions) Run(ctx context.Context, _ []string) error {
configure := true

if opts.project.IsConfigured(targ) {
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:")
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:", func() {})
if err != nil {
return err
}
Expand Down
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
2 changes: 1 addition & 1 deletion internal/cli/kraft/menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (opts *MenuOptions) Run(ctx context.Context, _ []string) error {
configure := true

if opts.project.IsConfigured(targ) {
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:")
configure, err = confirm.NewConfirm("project already configured, are you sure you want to rerun the configure step:", 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 9cd123f

Please sign in to comment.