Giter Site home page Giter Site logo

inquirer-tree-prompt's Introduction

Inquirer Tree Prompt

Heavily based on inquirer-file-tree-selection by anc95.

QuickDemo

QuickDemo

Install

npm install inquirer-tree-prompt

Usage

const TreePrompt = require('inquirer-tree-prompt');

inquirer.registerPrompt('tree', TreePrompt);

inquirer.prompt({
    type: 'tree',
    ...
})

Options

Takes type, name, message, tree, [filter, validate, transformer, pageSize, loop, onlyShowValid, hideChildrenOfValid, multiple] properties.

The extra options that this plugin provides are:

  • tree: (Array) list of tree items or (optionally asynchronous) function to obtain them; items are strings or objects with:

    • name: (String) to display in list; must provide this or value
    • value: (String) to put in answers hash; must provide this or name
    • short: (String) to display after selection
    • open: (Boolean) whether the item is expanded or collapsed
    • children: (Array or Function) list of child tree items or (optionally asynchronous) function to obtain them; function may return replacement item instead of just list of children
  • onlyShowValid: (Boolean) if true, will only show valid items (if validate is provided). Default: false.

  • hideChildrenOfValid: (Boolean) if true, will hide children of valid items (if validate is provided). Default: false.

  • transformer: (Function) a hook function to transform the display of item's value (when name is not given).

  • multiple: (Boolean) if true, will enable to select multiple items. Default: false.

Example

const inquirer = require('inquirer');
const TreePrompt = require('inquirer-tree-prompt');

inquirer.registerPrompt('tree', TreePrompt);

inquirer
    .prompt([
        {
            type: 'tree',
            name: 'location',
            message: 'Where is my phone?',
            tree: [
                {
                    value: "in the house",
                    open: true,
                    children: [
                        {
                            value: "in the living room",
                            children: [
                                "on the sofa",
                                "on the TV cabinet"
                            ]
                        },
                        {
                            value: "in the bedroom",
                            children: [
                                "under the bedclothes",
                                "on the bedside table"
                            ]
                        },
                        "in the bathroom"
                    ]
                },
                {
                    value: "in the car",
                    children: [
                        "on the dash",
                        "in the compartment",
                        "on the seat"
                    ]
                }
            ]
        }
    ])
    .then(answers => {
        console.log(JSON.stringify(answers))
    });

inquirer-tree-prompt's People

Contributors

insightfuls avatar willowmt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.