summaryrefslogtreecommitdiff
path: root/node_modules/prompt/examples/dynamic-ask-prompt.js
blob: 194e1ef1ffd89fc0d9bd4f5accbda73b204f546b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
});