Skip to content

feat(confirm): add --show-output#427

Merged
caarlos0 merged 2 commits intocharmbracelet:mainfrom
vahnrr:confirm-show-output
Dec 12, 2024
Merged

feat(confirm): add --show-output#427
caarlos0 merged 2 commits intocharmbracelet:mainfrom
vahnrr:confirm-show-output

Conversation

@vahnrr
Copy link
Copy Markdown
Contributor

@vahnrr vahnrr commented Sep 18, 2023

Fixes nothing, this is a feature I found missing from a specific use case I had in mind.

Changes

Adds the --show-output flag to gum confirm which prints the prompt and the chosen action to STDOUT.

gum confirm --show-output 'Do you agree?'
# Do you agree? Yes

gum confirm --show-output 'Do you agree?'
# Do you agree? No
# exit status 1

This merge adds 2 commits, only the first one (4f9235b) is required for the feature to work.
Since the feature doesn't affect confirm/confirm.go I feel like the second (432182f) isn't necessary, but I still included it in case I misunderstood the purpose of the model structure.

Copy link
Copy Markdown
Contributor

@MikaelFangel MikaelFangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some suggestions to help fix your linting error.

Also, you can check if it passes linting before pushing by using golangci-lint run

Comment thread confirm/command.go Outdated
Comment thread confirm/command.go Outdated
Comment on lines 39 to 48
} else {
os.Exit(1)
if o.ShowOutput {
confirmationText := m.(model).negative
if m.(model).confirmation {
confirmationText = m.(model).affirmative
}
fmt.Println(m.(model).prompt, confirmationText)
}

if m.(model).confirmation {
os.Exit(0)
} else {
os.Exit(1)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should remove the else and outdent the code and also the last else statement can be outdented as well.

The code will look something like this.

	}

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

	if m.(model).confirmation {
		os.Exit(0)
	}

	os.Exit(1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have missed the CI result notifications, really sorry.
This should be fixed as per you suggestions, thanks!

Regarding the model structure, do you think this commit is necessary?

@caarlos0
Copy link
Copy Markdown
Contributor

this looks good! can you fix the conflicts? if not, I can re-implement it on main...

@vahnrr vahnrr force-pushed the confirm-show-output branch from 2bb47ec to 3d74294 Compare December 12, 2024 18:35
@vahnrr
Copy link
Copy Markdown
Contributor Author

vahnrr commented Dec 12, 2024

No problem, it should be up to date now

@caarlos0 caarlos0 merged commit d1bfd56 into charmbracelet:main Dec 12, 2024
@caarlos0
Copy link
Copy Markdown
Contributor

thanks @vahnrr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants