Skip to content

Commit

Permalink
feat(confirm): add --show-output (#427)
Browse files Browse the repository at this point in the history
* feat(confirm): add `--show-output`

* feat(confirm): add `--show-output` model

---------

Co-authored-by: vahnrr <vahnrr@pm.me>
  • Loading branch information
vahnrr and vahnrr authored Dec 12, 2024
1 parent 74c1079 commit d1bfd56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions confirm/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (o Options) Run() error {
m := model{
affirmative: o.Affirmative,
negative: o.Negative,
showOutput: o.ShowOutput,
confirmation: o.Default,
defaultSelection: o.Default,
keys: defaultKeymap(o.Affirmative, o.Negative),
Expand All @@ -38,6 +39,14 @@ func (o Options) Run() error {
return fmt.Errorf("unable to confirm: %w", err)
}

if o.ShowOutput {
confirmationText := m.negative
if m.confirmation {
confirmationText = m.affirmative
}
fmt.Println(m.prompt, confirmationText)
}

m = tm.(model)
if m.confirmation {
return nil
Expand Down
1 change: 1 addition & 0 deletions confirm/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type model struct {
help help.Model
keys keymap

showOutput bool
confirmation bool

defaultSelection bool
Expand Down
1 change: 1 addition & 0 deletions confirm/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// Options is the customization options for the confirm command.
type Options struct {
Default bool `help:"Default confirmation action" default:"true"`
ShowOutput bool `help:"Print prompt and chosen action to output" default:"false"`
Affirmative string `help:"The title of the affirmative action" default:"Yes"`
Negative string `help:"The title of the negative action" default:"No"`
Prompt string `arg:"" help:"Prompt to display." default:"Are you sure?"`
Expand Down

0 comments on commit d1bfd56

Please sign in to comment.