https://github.com/anc95/inquirer-file-tree-selection
inquirer prompt for select a file or dir by file tree
https://github.com/anc95/inquirer-file-tree-selection
inquirer inquirer-plugin tree-selection
Last synced: 6 months ago
JSON representation
inquirer prompt for select a file or dir by file tree
- Host: GitHub
- URL: https://github.com/anc95/inquirer-file-tree-selection
- Owner: anc95
- Created: 2019-06-21T08:22:06.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-06-13T14:56:30.000Z (over 2 years ago)
- Last Synced: 2025-04-02T12:49:52.075Z (6 months ago)
- Topics: inquirer, inquirer-plugin, tree-selection
- Language: TypeScript
- Homepage:
- Size: 3.56 MB
- Stars: 51
- Watchers: 2
- Forks: 26
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## Inquirer File Tree Selection Prompt
[](https://github.com/anc95/inquirer-file-tree-selection/actions/workflows/npm-publish.yml)
### QuickDemo
### Install
```sh
npm install inquirer-file-tree-selection-prompt
```> If you are still using CJS, please install `inquirer-file-tree-selection-prompt@^1`
### Usage
```js
inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)inquirer.prompt({
type: 'file-tree-selection',
...
})
```### Options
Takes `type`, `name`, `message`, [`filter`, `validate`, `transformer`, `default`, `pageSize`, `onlyShowDir`, `onlyShowValid`, `hideChildrenOfValid`, `root`, `hideRoot`, `multiple`, `enableGoUpperDirector`] properties.The extra options that this plugin provides are:
- `onlyShowDir`: (Boolean) if true, will only show directory. Default: false.
- `root`: (String) it is the root of file tree. Default: process.cwd().
- `onlyShowValid`: (Boolean) if true, will only show valid files (if `validate` is provided). Default: false.
- `hideChildrenOfValid`: (Boolean) if true, will hide children of valid directories (if `validate` is provided). Default: false.
- `transformer`: (Function) a hook function to transform the display of directory or file name.
- `multiple`: (Boolean) if true, will enable to select multiple files. Default: false.
- `enableGoUpperDirectory`: (Boolean) Show `..` in inside root dir, and the user can press **space** on it to go upper directory. Default: false.When `multiple` is enabled, `default` should be `string[]` type, otherwise it's `string` type.
### Typescript Support> version >= 1.0.16
1. Install `@types/inquirer`
2. Ensure you have registered with `file-tree-selection`
```js
inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
```3. And you will get type support when you code in IDE

### Example
ESM (version ^2)
```js
import inquirer from 'inquirer'
import inquirerFileTreeSelection from 'inquirer-file-tree-selection-prompt'inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
inquirer
.prompt([
{
type: 'file-tree-selection',
name: 'file'
}
])
.then(answers => {
console.log(JSON.stringify(answers))
});
```CJS (version ^1 and <2)
```js
const inquirer = require('inquirer')
const inquirerFileTreeSelection = require('inquirer-file-tree-selection-prompt')inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
inquirer
.prompt([
{
type: 'file-tree-selection',
name: 'file'
}
])
.then(answers => {
console.log(JSON.stringify(answers))
});
```[More examples](./example/)