plop icon indicating copy to clipboard operation
plop copied to clipboard

Can't bypass a checklist prompt without selecting at least one option

Open bradgarropy opened this issue 2 years ago • 5 comments

Example Repo

Bypassing Checklist Prompts With No Options Selected

I created a minimal reproduction of the issue by creating a pizza generator where you select from three possible toppings.

The goal is to be able to bypass the checklist prompt and select none of the toppings.
Or in pizza terms, I want to order a cheese pizza. 🍕

npm run plop

? Choose your toppings. (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
>( ) pepperoni
 ( ) sausage
 ( ) onions

PASS

npm run plop pepperoni

✔  -> {"toppings":["pepperoni"]}

PASS

npm run plop pepperoni,sausage,onions

✔  -> {"toppings":["pepperoni","sausage","onions"]}

FAIL

In this case, I would expect to be able to bypass the checklist prompt by including something like an empty string ("") or an empty array ([]).

npm run plop ""

✔  -> {"toppings":[]}

bradgarropy avatar Jul 02 '22 02:07 bradgarropy

May you need to hide toppings with when:false property based on previous value selected.

JSDUNIYA avatar Aug 29 '22 01:08 JSDUNIYA

In my actual use case, the prompt in question doesn't rely on previous prompts, much like this pizza example.

bradgarropy avatar Aug 29 '22 02:08 bradgarropy

yeah, it look like we need to add a case in the checkbox logic for passing "no value". we split the input value on ,, so I think it would make sense to just check for an array of length 1, containing an empty string.

https://github.com/plopjs/plop/blob/master/packages/node-plop/src/prompt-bypass.js#L82

amwmedia avatar Aug 29 '22 14:08 amwmedia

Thanks for pointing me in the right direction @amwmedia, I'll get a pull request up soon!

bradgarropy avatar Aug 29 '22 14:08 bradgarropy

I opened #354 to address this issue, I hope it covers the use case!

/cc @amwmedia @crutchcorn

bradgarropy avatar Aug 30 '22 02:08 bradgarropy