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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ export abstract class SfCommand<T> extends Command {
*
* @param message text to display. Do not include a question mark.
* @param ms milliseconds to wait for user input. Defaults to 10s.
* @param defaultAnswer boolean to set the default answer to. Defaults to true.
* @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.

return this.prompter.confirm(message, ms, defaultAnswer);
}

/**
Expand Down