blob: 347c86a490d3aeafff8dfbbd2d7c051b994f50c9 [file] [log] [blame]
{
"name": "prompt",
"description": "A beautiful command-line prompt for node.js",
"version": "0.2.11",
"author": {
"name": "Nodejitsu Inc.",
"email": "info@nodejitsu.com"
},
"maintainers": [
{
"name": "indexzero",
"email": "charlie@nodejitsu.com"
},
{
"name": "jesusabdullah",
"email": "josh@nodejitsu.com"
}
],
"repository": {
"type": "git",
"url": "http://github.com/flatiron/prompt.git"
},
"dependencies": {
"pkginfo": "0.x.x",
"read": "1.0.x",
"revalidator": "0.1.x",
"utile": "0.2.x",
"winston": "0.6.x"
},
"devDependencies": {
"vows": "0.7.0"
},
"main": "./lib/prompt",
"scripts": {
"test": "vows test/prompt-test.js --spec",
"test-all": "vows --spec"
},
"engines": {
"node": ">= 0.6.6"
},
"readme": "# prompt [![Build Status](https://secure.travis-ci.org/flatiron/prompt.png)](http://travis-ci.org/flatiron/prompt)\n\nA beautiful command-line prompt for node.js\n\n## Features\n\n* prompts the user for input\n* supports validation and defaults\n* hides passwords\n\n## Usage\nUsing 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][0] that you should examine for detailed usage.\n\n### Getting Basic Prompt Information\nGetting started with `prompt` is easy. Lets take a look at `examples/simple-prompt.js`:\n\n``` js\n var prompt = require('prompt');\n\n //\n // Start the prompt\n //\n prompt.start();\n\n //\n // Get two properties from the user: username and email\n //\n prompt.get(['username', 'email'], function (err, result) {\n //\n // Log the results.\n //\n console.log('Command-line input received:');\n console.log(' username: ' + result.username);\n console.log(' email: ' + result.email);\n });\n```\n\nThis will result in the following command-line output:\n\n```\n $ node examples/simple-prompt.js \n prompt: username: some-user\n prompt: email: some-user@some-place.org\n Command-line input received:\n username: some-user\n email: some-user@some-place.org\n```\n\n### Prompting with Validation, Default Values, and More (Complex Properties)\nIn addition to prompting the user with simple string prompts, there is a robust API for getting and validating complex information from a command-line prompt. Here's a quick sample:\n\n``` js\n var schema = {\n properties: {\n name: {\n pattern: /^[a-zA-Z\\s\\-]+$/,\n message: 'Name must be only letters, spaces, or dashes',\n required: true\n },\n password: {\n hidden: true\n }\n }\n };\n\n //\n // Start the prompt\n //\n prompt.start();\n\n //\n // Get two properties from the user: email, password\n //\n prompt.get(schema, function (err, result) {\n //\n // Log the results.\n //\n console.log('Command-line input received:');\n console.log(' name: ' + result.name);\n console.log(' password: ' + result.password);\n });\n```\n\nPretty easy right? The output from the above script is: \n\n```\n $ node examples/property-prompt.js\n prompt: name: nodejitsu000\n error: Invalid input for name\n error: Name must be only letters, spaces, or dashes\n prompt: name: Nodejitsu Inc\n prompt: password: \n Command-line input received:\n name: Nodejitsu Inc\n password: some-password \n```\n\n## Valid Property Settings\n`prompt` understands JSON-schema with a few extra parameters and uses [revalidator](https://github.com/flatiron/revalidator) for validation.\n\nHere's an overview of the properties that may be used for validation and prompting controls:\n\n``` js\n {\n description: 'Enter your password', // Prompt displayed to the user. If not supplied name will be used.\n type: 'string', // Specify the type of input to expect.\n pattern: /^\\w+$/, // Regular expression that input must be valid against.\n message: 'Password must be letters', // Warning message to display if validation fails.\n hidden: true, // If true, characters entered will not be output to console.\n default: 'lamepassword', // Default value to use if no value is entered.\n required: true // If true, value entered must be non-empty.\n before: function(value) { return 'v' + value; } // Runs before node-prompt callbacks. It modifies user's input\n }\n```\n\nAlternatives to `pattern` include `format` and `conform`, as documented in [revalidator](https://github.com/flatiron/revalidator).\n\nUsing `type: 'array'` has some special cases.\n\n- `description` will not work in the schema if `type: 'array'` is defined.\n- `maxItems` takes precedence over `minItems`.\n- Arrays that do not have `maxItems` defined will require users to `SIGINT` (`^C`) before the array is ended.\n- If `SIGINT` (`^C`) is triggered before `minItems` is met, a validation error will appear. This will require users to `SIGEOF` (`^D`) to end the input.\n\nFor more information on things such as `maxItems` and `minItems`, refer to the [revalidator](https://github.com/flatiron/revalidator) repository.\n\n### Alternate Validation API:\n\nPrompt, in addition to iterating over JSON-Schema properties, will also happily iterate over an array of validation objects given an extra 'name' property:\n\n```js\n var prompt = require('../lib/prompt');\n\n //\n // Start the prompt\n //\n prompt.start();\n\n //\n // Get two properties from the user: username and password\n //\n prompt.get([{\n name: 'username',\n required: true\n }, {\n name: 'password',\n hidden: true,\n conform: function (value) {\n return true;\n }\n }], function (err, result) {\n //\n // Log the results.\n //\n console.log('Command-line input received:');\n console.log(' username: ' + result.username);\n console.log(' password: ' + result.password);\n });\n```\n\n### Backward Compatibility\n\nNote 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.\n\n### Skipping Prompts\n\nSometimes power users may wish to skip promts and specify all data as command line options. \nif a value is set as a property of `prompt.override` prompt will use that instead of \nprompting the user.\n\n``` js\n //prompt-override.js\n\n var prompt = require('prompt'),\n optimist = require('optimist')\n\n //\n // set the overrides\n //\n prompt.override = optimist.argv\n\n //\n // Start the prompt\n //\n prompt.start();\n\n //\n // Get two properties from the user: username and email\n //\n prompt.get(['username', 'email'], function (err, result) {\n //\n // Log the results.\n //\n console.log('Command-line input received:');\n console.log(' username: ' + result.username);\n console.log(' email: ' + result.email);\n })\n\n //: node prompt-override.js --username USER --email EMAIL\n```\n\n\n### Adding Properties to an Object \nA 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: \n\n``` js\n var obj = {\n password: 'lamepassword',\n mindset: 'NY'\n }\n\n //\n // Log the initial object.\n //\n console.log('Initial object to be extended:');\n console.dir(obj);\n\n //\n // Add two properties to the empty object: username and email\n //\n prompt.addProperties(obj, ['username', 'email'], function (err) {\n //\n // Log the results.\n //\n console.log('Updated object received:');\n console.dir(obj);\n });\n```\n\n## Customizing your prompt\nAside from changing `property.message`, you can also change `prompt.message`\nand `prompt.delimiter` to change the appearance of your prompt.\n\nThe basic structure of a prompt is this:\n\n``` js\nprompt.message + prompt.delimiter + property.message + prompt.delimiter;\n```\n\nThe default `prompt.message` is \"prompt,\" the default `prompt.delimiter` is\n\": \", and the default `property.message` is `property.name`.\nChanging these allows you to customize the appearance of your prompts! In\naddition, prompt supports ANSI color codes via the\n[colors module](https://github.com/Marak/colors.js) for custom colors. For a\nvery colorful example:\n\n``` js\n var prompt = require(\"prompt\");\n\n //\n // Setting these properties customizes the prompt.\n //\n prompt.message = \"Question!\".rainbow;\n prompt.delimiter = \"><\".green;\n\n prompt.start();\n\n prompt.get({\n properties: {\n name: {\n description: \"What is your name?\".magenta\n }\n }\n }, function (err, result) {\n console.log(\"You said your name is: \".cyan + result.name.cyan);\n });\n```\n\nIf you don't want colors, you can set\n\n```js\nvar prompt = require('prompt');\n\nprompt.colors = false;\n```\n\n## Installation\n\n``` bash\n $ [sudo] npm install prompt\n```\n\n## Running tests\n\n``` bash \n $ npm test\n```\n\n#### License: MIT\n#### Author: [Charlie Robbins](http://github.com/indexzero)\n#### Contributors: [Josh Holbrook](http://github.com/jesusabdullah), [Pavan Kumar Sunkara](http://github.com/pksunkara)\n\n[0]: https://github.com/flatiron/prompt/tree/master/examples\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/flatiron/prompt/issues"
},
"_id": "prompt@0.2.11",
"_from": "prompt@0.2.11"
}