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

Cannot bypass list prompt when its value is an object #284

Closed
knikolov-nuvolo opened this issue Sep 28, 2021 · 2 comments · Fixed by plopjs/node-plop#209
Closed

Cannot bypass list prompt when its value is an object #284

knikolov-nuvolo opened this issue Sep 28, 2021 · 2 comments · Fixed by plopjs/node-plop#209

Comments

@knikolov-nuvolo
Copy link
Contributor

I have a list prompt, and each item in the list has an object set for its value, e.g.:

{
  type: 'list',
  name: 'folder',
  message: 'Select folder:',
  choices: [
    {
      name: 'components',
      short: 'components',
      value: {
        name: 'components',
        relativePath: './src/components',
        absolutePath: '/Users/knikolov/Projects/my-project/src/components',
      },
    },
    {
      name: 'test',
      short: 'test',
      value: {
        name: 'test',
        relativePath: './test',
        absolutePath: '/Users/knikolov/Projects/my-project/test',
      },
    },
  ]
}

When I try to bypass that prompt with any of these, it fails.

plop template 0
plop template components

After debugging, I found out that the reason is because of this line:
https://github.com/plopjs/node-plop/blob/1c09ef314eed9f16a8071a2870c6df472201be02/src/prompt-bypass.js#L27

Here, it expects that the value is always string and tries to call toLowerCase() without checking its type.
If we add typeof choiceValue === 'string' it should be possible to match choice values by name and/or index.

As a temporary solution I added toLowerCase: () => name to the value (which is an ugly solution).

@crutchcorn
Copy link
Member

Oh, this is a good catch!

Thanks for looking into the code to find the solution - that would've taken me a while, admittedly.

Your solution of typeof == 'string' seems like a great solution to me. Any chance you'd want to open a PR? :)

@knikolov-nuvolo
Copy link
Contributor Author

@crutchcorn
PR created: node-plop/pull/209 :)

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 a pull request may close this issue.

2 participants