README.md

prompt

A beautiful command-line prompt for node.js

Features

prompts the user for input

supports validation and defaults

hides passwords

Usage

Using prompt is relatively straight forward. There are two core methods you should be aware of: prompt.get() and prompt.addProperties(). There methods take strings representing property names in addition to objects for complex property validation (and more). There are a number of examples that you should examine for detailed usage.

Getting Basic Prompt Information

Getting started with prompt is easy. Lets take a look at examples/simple-prompt.js:

Valid Property Settings

prompt understands JSON-schema with a few extra parameters and uses revalidator for validation.

Here's an overview of the properties that may be used for validation and prompting controls:

{
description:'Enter your password', // Prompt displayed to the user. If not supplied name will be used.
pattern:/^\w+$/, // Regular expression that input must be valid against.
message:'Password must be letters', // Warning message to display if validation fails.
hidden:true, // If true, characters entered will not be output to console.
default:'lamepassword', // Default value to use if no value is entered.
required:true// If true, value entered must be non-empty.
}

Alternatives to pattern include format and conform, as documented in revalidator.

Alternate Validation API:

Prompt, in addition to iterating over JSON-Schema properties, will also happily iterate over an array of validation objects given an extra 'name' property:

Backward Compatibility

Note that, while this structure is similar to that used by prompt 0.1.x, that the object properties use the same names as in JSON-Schema. prompt 0.2.x is backward compatible with prompt 0.1.x except for asynchronous validation.

Skipping Prompts

Sometimes power users may wish to skip promts and specify all data as command line options.
if a value is set as a property of prompt.override prompt will use that instead of
prompting the user.

Adding Properties to an Object

A common use-case for prompting users for data from the command-line is to extend or create a configuration object that is passed onto the entry-point method for your CLI tool. prompt exposes a convenience method for doing just this:

Customizing your prompt

Aside from changing property.message, you can also change prompt.message
and prompt.delimiter to change the appearance of your prompt.

The basic structure of a prompt is this:

prompt.message+prompt.delimiter+property.message+prompt.delimiter;

The default prompt.message is "prompt," the default prompt.delimiter is
": ", and the default property.message is property.name.
Changing these allows you to customize the appearance of your prompts! In
addition, prompt supports ANSI color codes via the
colors module for custom colors. For a
very colorful example: