Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default answer param to confirm #215

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

peternhale
Copy link
Collaborator

@W-12521197@

* @return true if the user confirms, false if they do not.
*/
public async confirm(message: string, ms = 10000): Promise<boolean> {
return this.prompter.confirm(message, ms);
public async confirm(message: string, ms = 10000, defaultAnswer = true): Promise<boolean> {
Copy link
Member

@cristiand391 cristiand391 Feb 9, 2023

Choose a reason for hiding this comment

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

UIs usually ask for confirmation before doing an expensive/destructive operation and default to no to ensure the user really wants to do it.

Let's say my plugin has a bunch of commands that delete stuff in an org, I would have to set defaultAnswer to no on each command. It's easy to forget to do it and may cause a unexpected outcome for the user.

Since the prompter is the one defaulting to true and it's public this change would require a major bump:
https://github.com/salesforcecli/sf-plugins-core/blob/main/src/ux/prompter.ts#L61

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cristiand391 This is a utility function and it has no concept of what the implications are of a yes or no answer. Those decisions are best done by the caller. Making the default true is protecting backward compatibility.

@cristiand391 cristiand391 merged commit dc40d45 into main Feb 9, 2023
@cristiand391 cristiand391 deleted the phale/confirm-default branch February 9, 2023 20:31
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.

2 participants