anc95 / inquirer-file-tree-selection

inquirer prompt for select a file or dir by file tree
49 stars 26 forks source link

Expose filter and validate API #3

Closed MasGaNo closed 4 years ago

MasGaNo commented 4 years ago

Hi!

First of all, nice job for this plugin, it works very well!

Then, is it possible to have filter and validate method exposed in the prompt configuration like for the others built-in inquirer prompt type?

Currently, when I'm doing something like:

   const answer = await inquirer.prompt([
      {
        type: 'file-tree-selection',
        message: 'Choose folder',
        onlyShowDir: true,
        name: 'srcDir',
        filter: (input) => {
          return new Promise(() => {
            throw new Error(input);
            return input;            
          });
        }
      }
    ]);

Filter is not called.

I have currently an easy workaround, but it will be really nice to configure this prompt like the others one.

What do you think?

anc95 commented 4 years ago

@MasGaNo thx for your advice. i have done it and publish it as inquirer-file-tree-selection-prompt@1.0.3 you can install it with

npm i  inquirer-file-tree-selection-prompt@1.0.3

usage

const answer = await inquirer.prompt([
      {
        type: 'file-tree-selection',
        message: 'Choose folder',
        onlyShowDir: true,
        name: 'srcDir',
        filter: (input) => {
          return 'filteredValue';
        },
        validate: () => {
          return 'invalid answer';
        }
      }
    ]);
MasGaNo commented 4 years ago

Works like a charm 🙂

Thanks ^^