dynamic-ask-prompt.js
795 Bytes
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);
});