anc95 / inquirer-file-tree-selection

inquirer prompt for select a file or dir by file tree
49 stars 25 forks source link
inquirer inquirer-plugin tree-selection

Inquirer File Tree Selection Prompt

Node.js Package

QuickDemo

QuickDemo

Install

npm install inquirer-file-tree-selection-prompt

If you are still using CJS, please install inquirer-file-tree-selection-prompt@^1

Usage

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:

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

inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
  1. And you will get type support when you code in IDE

ts

Example

ESM (version ^2)

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)

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