summaryrefslogtreecommitdiff
path: root/node_modules/prompt/examples
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prompt/examples')
-rw-r--r--node_modules/prompt/examples/add-properties.js35
-rw-r--r--node_modules/prompt/examples/color.js19
-rw-r--r--node_modules/prompt/examples/dynamic-ask-prompt.js38
-rw-r--r--node_modules/prompt/examples/existing-properties.js35
-rw-r--r--node_modules/prompt/examples/history.js44
-rw-r--r--node_modules/prompt/examples/nested-properties-prompt.js37
-rw-r--r--node_modules/prompt/examples/old-schema.js36
-rw-r--r--node_modules/prompt/examples/override-validation.js52
-rw-r--r--node_modules/prompt/examples/password.js42
-rw-r--r--node_modules/prompt/examples/prompt-override.js36
-rw-r--r--node_modules/prompt/examples/prompt-streamline._js32
-rw-r--r--node_modules/prompt/examples/property-prompt.js45
-rw-r--r--node_modules/prompt/examples/simple-prompt.js25
-rw-r--r--node_modules/prompt/examples/types.js20
-rw-r--r--node_modules/prompt/examples/yes-or-no-prompt.js32
15 files changed, 528 insertions, 0 deletions
diff --git a/node_modules/prompt/examples/add-properties.js b/node_modules/prompt/examples/add-properties.js
new file mode 100644
index 0000000..1a56176
--- /dev/null
+++ b/node_modules/prompt/examples/add-properties.js
@@ -0,0 +1,35 @@
+/*
+ * add-properties.js: Example of how to add properties to an object using prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+var obj = {
+ password: 'lamepassword',
+ mindset: 'NY'
+}
+
+//
+// Log the initial object.
+//
+console.log('Initial object to be extended:');
+console.dir(obj);
+
+//
+// Add two properties to the empty object: username and email
+//
+prompt.addProperties(obj, ['username', 'email'], function (err) {
+ //
+ // Log the results.
+ //
+ console.log('Updated object received:');
+ console.dir(obj);
+}); \ No newline at end of file
diff --git a/node_modules/prompt/examples/color.js b/node_modules/prompt/examples/color.js
new file mode 100644
index 0000000..7c63112
--- /dev/null
+++ b/node_modules/prompt/examples/color.js
@@ -0,0 +1,19 @@
+var prompt = require("../lib/prompt");
+var colors = require("colors/safe");
+//
+// Setting these properties customizes the prompt.
+//
+prompt.message = colors.rainbow("Question!");
+prompt.delimiter = colors.green("><");
+
+prompt.start();
+
+prompt.get({
+ properties: {
+ name: {
+ description: colors.magenta("What is your name?")
+ }
+ }
+}, function (err, result) {
+ console.log(colors.cyan("You said your name is: " + result.name));
+});
diff --git a/node_modules/prompt/examples/dynamic-ask-prompt.js b/node_modules/prompt/examples/dynamic-ask-prompt.js
new file mode 100644
index 0000000..194e1ef
--- /dev/null
+++ b/node_modules/prompt/examples/dynamic-ask-prompt.js
@@ -0,0 +1,38 @@
+/*
+ * dynamic-ask-prompt.js: Dynamically decide whether to display prompt.
+ */
+
+var prompt = require('../lib/prompt');
+
+var schema = {
+ properties: {
+ proxy: {
+ description: 'Proxy url'
+ },
+ proxyCredentials: {
+ description: 'Proxy credentials',
+ ask: function() {
+ // only ask for proxy credentials if a proxy was set
+ return prompt.history('proxy').value > 0;
+ }
+ }
+ }
+};
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get one or two properties from the user, depending on
+// what the user answered for proxy
+//
+prompt.get(schema, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' proxy: ' + result.proxy);
+ console.log(' credentials: ' + result.proxyCredentials);
+});
diff --git a/node_modules/prompt/examples/existing-properties.js b/node_modules/prompt/examples/existing-properties.js
new file mode 100644
index 0000000..d87503b
--- /dev/null
+++ b/node_modules/prompt/examples/existing-properties.js
@@ -0,0 +1,35 @@
+/*
+ * existing-properties.js: Example of using prompt with predefined properties.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+prompt.properties = {
+ email: {
+ format: 'email',
+ message: 'Must be a valid email address'
+ },
+ password: {
+ hidden: true
+ }
+};
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: email, password
+//
+prompt.get(['email', 'password'], function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' email: ' + result.email);
+ console.log(' password: ' + result.password);
+});
diff --git a/node_modules/prompt/examples/history.js b/node_modules/prompt/examples/history.js
new file mode 100644
index 0000000..fd4369d
--- /dev/null
+++ b/node_modules/prompt/examples/history.js
@@ -0,0 +1,44 @@
+/*
+ * history.js: Example of using the prompt history capabilities.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+var properties = {
+ properties: {
+ animal: {
+ description: 'Enter an animal',
+ default: 'dog',
+ pattern: /dog|cat/
+ },
+ sound: {
+ description: 'What sound does this animal make?',
+ conform: function (value) {
+ var animal = prompt.history(0).value;
+
+ return animal === 'dog' && value === 'woof'
+ || animal === 'cat' && value === 'meow';
+ }
+ }
+ }
+}
+
+//
+// Get two properties from the user
+//
+prompt.get(properties, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' animal: ' + result.animal);
+ console.log(' sound: ' + result.sound);
+});
diff --git a/node_modules/prompt/examples/nested-properties-prompt.js b/node_modules/prompt/examples/nested-properties-prompt.js
new file mode 100644
index 0000000..25106a2
--- /dev/null
+++ b/node_modules/prompt/examples/nested-properties-prompt.js
@@ -0,0 +1,37 @@
+/*
+ * property-prompt.js: Example of using prompt with complex properties.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+var schema = {
+ properties: {
+ url: {
+ required: true,
+ format: 'url'
+ },
+ auth: {
+ properties: {
+ username: {
+ required: true
+ },
+ password: {
+ required: true,
+ hidden: true
+ }
+ }
+ }
+ }
+};
+
+prompt.start();
+
+prompt.get(schema, function (err, result) {
+ console.log('Command-line input received:');
+ console.log(' url: ' + result.url);
+ console.log(' auth:username: ' + result.auth.username);
+ console.log(' auth:password: ' + result.auth.password);
+});
diff --git a/node_modules/prompt/examples/old-schema.js b/node_modules/prompt/examples/old-schema.js
new file mode 100644
index 0000000..631b7b5
--- /dev/null
+++ b/node_modules/prompt/examples/old-schema.js
@@ -0,0 +1,36 @@
+/*
+ * simple-prompt.js: Simple example of using prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: username and email
+//
+prompt.get([
+ {
+ name: 'username',
+ validator: /^[a-z]+$/,
+ warning: 'Username should consist only lowercase alphabets',
+ empty: false
+ },
+ {
+ name: 'email',
+ message: 'Email Address'
+ }
+], function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' username: ' + result.username);
+ console.log(' email: ' + result.email);
+});
diff --git a/node_modules/prompt/examples/override-validation.js b/node_modules/prompt/examples/override-validation.js
new file mode 100644
index 0000000..0ca9ddd
--- /dev/null
+++ b/node_modules/prompt/examples/override-validation.js
@@ -0,0 +1,52 @@
+/*
+ * override-validation.js: Example of using prompt with complex properties and command-line input.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt'),
+ optimist = require('optimist');
+
+var schema = {
+ properties: {
+ name: {
+ pattern: /^[a-zA-Z\s-]+$/,
+ message: 'Name must be only letters, spaces, or dashes',
+ required: true
+ },
+ email: {
+ name: 'email',
+ format: 'email',
+ message: 'Must be a valid email address'
+ }
+ }
+};
+
+//
+// Set the overrides
+//
+prompt.override = optimist.argv
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: email, password
+//
+prompt.get(schema, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' name: ' + result.name);
+ console.log(' email: ' + result.email);
+});
+
+// try running
+// $ node ./override-validation.js --name USER --email EMAIL
+// You will only be asked for email because it's invalid
+// $ node ./override-validation.js --name h$acker --email me@example.com
+// You will only be asked for name becasue it's invalid
diff --git a/node_modules/prompt/examples/password.js b/node_modules/prompt/examples/password.js
new file mode 100644
index 0000000..e8015e6
--- /dev/null
+++ b/node_modules/prompt/examples/password.js
@@ -0,0 +1,42 @@
+/*
+ * password.js: Simple example of using prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: username and password and password masked
+//
+prompt.get([{
+ name: 'username',
+ required: true
+ }, {
+ name: 'password',
+ hidden: true,
+ conform: function (value) {
+ return true;
+ }
+ }, {
+ name: 'passwordMasked',
+ hidden: true,
+ replace: '*',
+ conform: function (value) {
+ return true;
+ }
+ }], function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' username: ' + result.username);
+ console.log(' password: ' + result.password);
+ console.log(' passwordMasked: ' + result.passwordMasked);
+});
diff --git a/node_modules/prompt/examples/prompt-override.js b/node_modules/prompt/examples/prompt-override.js
new file mode 100644
index 0000000..7f2848b
--- /dev/null
+++ b/node_modules/prompt/examples/prompt-override.js
@@ -0,0 +1,36 @@
+var prompt = require('../lib/prompt'),
+ optimist;
+
+try {
+ optimist = require('optimist');
+} catch (err) {
+ throw new Error([
+ 'You need to install optimist before this example will work!',
+ 'Try: `npm install optimist`.'
+ ].join('\n'));
+}
+
+//
+// Set the overrides
+//
+prompt.override = optimist.argv
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: username and email
+//
+prompt.get(['username', 'email'], function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' username: ' + result.username);
+ console.log(' email: ' + result.email);
+ prompt.pause();
+})
+
+// $ node ./prompt-override.js --username USER --email EMAIL
diff --git a/node_modules/prompt/examples/prompt-streamline._js b/node_modules/prompt/examples/prompt-streamline._js
new file mode 100644
index 0000000..e7fef42
--- /dev/null
+++ b/node_modules/prompt/examples/prompt-streamline._js
@@ -0,0 +1,32 @@
+/*
+ * prompt-streamline._js: Example of how to use prompt with streamlinejs.
+ *
+ * calling syntax: _node prompt-streamline._js
+ *
+ */
+var prompt = require('../lib/prompt');
+
+function getSampleData(){
+ return [
+ {
+ name: 'username',
+ message: 'Enter a username'
+ }
+ ];
+};
+
+//
+// Start the prompt
+//
+prompt.start();
+
+function get_username_prompt(_){
+ console.log(prompt.get(getSampleData(), _).username);
+}
+
+get_username_prompt(_);
+
+//
+// Clean the prompt
+//
+prompt.stop(); \ No newline at end of file
diff --git a/node_modules/prompt/examples/property-prompt.js b/node_modules/prompt/examples/property-prompt.js
new file mode 100644
index 0000000..c8b343b
--- /dev/null
+++ b/node_modules/prompt/examples/property-prompt.js
@@ -0,0 +1,45 @@
+/*
+ * property-prompt.js: Example of using prompt with complex properties.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+var schema = {
+ properties: {
+ name: {
+ pattern: /^[a-zA-Z\s-]+$/,
+ message: 'Name must be only letters, spaces, or dashes',
+ required: true
+ },
+ email: {
+ name: 'email',
+ format: 'email',
+ message: 'Must be a valid email address'
+ },
+ password: {
+ required: true,
+ hidden: true
+ }
+ }
+};
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: email, password
+//
+prompt.get(schema, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' name: ' + result.name);
+ console.log(' email: ' + result.email);
+ console.log(' password: ' + result.password);
+});
diff --git a/node_modules/prompt/examples/simple-prompt.js b/node_modules/prompt/examples/simple-prompt.js
new file mode 100644
index 0000000..062e529
--- /dev/null
+++ b/node_modules/prompt/examples/simple-prompt.js
@@ -0,0 +1,25 @@
+/*
+ * simple-prompt.js: Simple example of using prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+//
+// Get two properties from the user: username and email
+//
+prompt.get(['username', 'email'], function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' username: ' + result.username);
+ console.log(' email: ' + result.email);
+}); \ No newline at end of file
diff --git a/node_modules/prompt/examples/types.js b/node_modules/prompt/examples/types.js
new file mode 100644
index 0000000..83f45a6
--- /dev/null
+++ b/node_modules/prompt/examples/types.js
@@ -0,0 +1,20 @@
+var prompt = require('../lib/prompt');
+
+prompt.start();
+
+prompt.get([{
+ name: 'integer',
+ type: 'integer',
+ required: true
+ }, {
+ name: 'number',
+ type: 'number',
+ required: true
+ }, {
+ name: 'boolean',
+ type: 'boolean',
+ required: true
+ }], function (err, result) {
+ console.log('Input received:');
+ console.log(JSON.stringify(result, null, 2));
+});
diff --git a/node_modules/prompt/examples/yes-or-no-prompt.js b/node_modules/prompt/examples/yes-or-no-prompt.js
new file mode 100644
index 0000000..512b556
--- /dev/null
+++ b/node_modules/prompt/examples/yes-or-no-prompt.js
@@ -0,0 +1,32 @@
+/*
+ * yes-or-no-prompt.js: Simple example of using prompt.
+ *
+ * (C) 2012, Nodejitsu Inc.
+ *
+ */
+
+var prompt = require('../lib/prompt');
+
+//
+// Start the prompt
+//
+prompt.start();
+
+var property = {
+ name: 'yesno',
+ message: 'are you sure?',
+ validator: /y[es]*|n[o]?/,
+ warning: 'Must respond yes or no',
+ default: 'no'
+};
+
+//
+// Get the simple yes or no property
+//
+prompt.get(property, function (err, result) {
+ //
+ // Log the results.
+ //
+ console.log('Command-line input received:');
+ console.log(' result: ' + result.yesno);
+}); \ No newline at end of file