Inquirer File Selector Prompt
A plugin for Inquirer, allowing users to navigate their file directories to select files.
Installation
npm install --save inquirer-file-selector-prompt
Usage
Register the prompt under any alias you prefer then use the prompt as you would any other inquirer prompt.
inquirer.registerPrompt('file-selector', require('inquirer-file-selector-prompt'));
inquirer.prompt({
type: 'file-selector',
...
})
Options
Takes type
, name
, message
, [filter
, validate
, default
, pageSize
, path
, extensions
, selectionType
, onlyShowMatchingExtensions
] properties.
The extra options that this plugin provides are:
- path
Type: string
Description: Starting directory for the prompt
Default: process.cwd()
- extensions
Type: Array<string>
Description: Array of valid extensions to pick from
Default: []
(any extension) - selectionType
Type: string
Description: Choose whether to select a file or directory
Valid options: ["file","folder","either"]
Default: "file"
- onlyShowMatchingExtensions
Type: boolean
Description: Select whether to hide files that do not match the specified valid extensions
Default: false
Example
const inquirer = require('inquirer');
const fileSelector = require('./index.js');
inquirer.registerPrompt('file-tree-selection', fileSelector);
inquirer
.prompt([
{
type: 'file-tree-selection',
name: 'file',
message: 'choose a file',
extensions: ['js']
}
])
.then(answers => {
console.log(JSON.stringify(answers));
});
License
This project is under the MIT license.