-
Notifications
You must be signed in to change notification settings - Fork 94
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
Allow customizing the cancel behaviour #100
Conversation
Will let @jessarcher take a look. 👍 |
Hey @weitzman, thanks for the PR! Very cool that you're adding Prompts to Drush!
I think making it configurable might be the go, otherwise, all existing projects using Prompts won't exit cleanly on We could add a handler in I'm thinking a static method on the Prompt::cancelUsing(fn () => throw new Exception); If no callback has been registered, the default What do you think? |
Sounds good to me. See latest push. I've confirmed this is working with the Drush PR. I looked at the tests and don't see a way to test this. I'm happy to add a test if anyone can think of one. |
Drafting until @jessarcher takes a look again. |
Thanks @weitzman! I've added a quick test. |
I'm coming from the Drush project, the CLI for Drupal. We are switching our prompts to use this package.
One minor gotcha is calling exit() when a user cancels a prompt. Prompts renders a nice Cancelled message and then calls exit(1) which triggers PHP shutdown handling. It would be more convenient if an Exception is thrown here, so implementing projects can react appropriately. A shutdown handler is too restricted in what it can do.
This PR is just a start so I can get feedback on the idea. Maybe we make the this behavior configurable?
Thanks for releasing Prompts as an independant package!