forked from aam229/inquirer-path
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.js
44 lines (40 loc) · 871 Bytes
/
simple.js
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
39
40
41
42
43
44
const fs = require('fs');
const inquirer = require('inquirer');
const PathPrompt = require('../lib').PathPrompt;
inquirer.registerPrompt('path', PathPrompt);
function exists(path) {
try {
fs.accessSync(path, fs.R_OK);
return true;
} catch (error) {
return false;
}
}
const questions = [
{
type: 'rawlist',
name: 'list',
message: 'Pick an option',
choices: ['hello', 'world'],
},
{
type: 'path',
name: 'path',
message: 'Enter a path',
default: process.cwd(),
validate: answer => exists(answer) ? true : 'The path does not exist',
},
{
type: 'confirm',
name: 'conf1',
message: 'Confirm once',
},
{
type: 'confirm',
name: 'conf2',
message: 'Confirm twice',
}
];
inquirer.prompt(questions)
.then(result => console.log(result.path))
.catch(err => console.error(err.stack));