inquirerer 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js DELETED
@@ -1,117 +0,0 @@
1
- var __assign = (this && this.__assign) || Object.assign || function(t) {
2
- for (var s, i = 1, n = arguments.length; i < n; i++) {
3
- s = arguments[i];
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
5
- t[p] = s[p];
6
- }
7
- return t;
8
- };
9
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __generator = (this && this.__generator) || function (thisArg, body) {
18
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
19
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
20
- function verb(n) { return function (v) { return step([n, v]); }; }
21
- function step(op) {
22
- if (f) throw new TypeError("Generator is already executing.");
23
- while (_) try {
24
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
25
- if (y = 0, t) op = [0, t.value];
26
- switch (op[0]) {
27
- case 0: case 1: t = op; break;
28
- case 4: _.label++; return { value: op[1], done: false };
29
- case 5: _.label++; y = op[1]; op = [0]; continue;
30
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
31
- default:
32
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
33
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
34
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
35
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
36
- if (t[2]) _.ops.pop();
37
- _.trys.pop(); continue;
38
- }
39
- op = body.call(thisArg, _);
40
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
41
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
42
- }
43
- };
44
- (function (factory) {
45
- if (typeof module === "object" && typeof module.exports === "object") {
46
- var v = factory(require, exports);
47
- if (v !== undefined) module.exports = v;
48
- }
49
- else if (typeof define === "function" && define.amd) {
50
- define(["require", "exports", "colors", "inquirer"], factory);
51
- }
52
- })(function (require, exports) {
53
- "use strict";
54
- var _this = this;
55
- Object.defineProperty(exports, "__esModule", { value: true });
56
- require("colors");
57
- var inquirer = require("inquirer");
58
- inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
59
- exports.required = function (questions) {
60
- return questions.map(function (q) {
61
- if (q.required && !q.validate) {
62
- q.validate = function (value) {
63
- if (!value) {
64
- return q.name + " is required";
65
- }
66
- return true;
67
- };
68
- }
69
- return q;
70
- });
71
- };
72
- exports.names = function (questions) {
73
- return questions.map(function (q) {
74
- q.message = "" + '['.white + q.name.blue + ']'.white + " " + q.message.green;
75
- return q;
76
- });
77
- };
78
- exports.filter = function (questions, answers) {
79
- var A = questions.map(function (q) { return q.name; });
80
- var B = Object.keys(answers);
81
- var diff = A.filter(function (x) { return !B.includes(x); });
82
- return A.filter(function (n) { return diff.includes(n); }).map(function (name) {
83
- return questions.find(function (o) { return o.name === name; });
84
- });
85
- };
86
- // converts argv._ into the answers when question specifies it
87
- exports._filter = function (questions, answers) {
88
- var _Qs = questions.filter(function (q) { return q.hasOwnProperty('_'); });
89
- var A = _Qs.map(function (v, i) { return i + ''; });
90
- var B = Object.keys(answers._ || []);
91
- var includes = A.filter(function (x) { return B.includes(x); });
92
- for (var i = 0; i < includes.length; i++) {
93
- answers[_Qs[i].name] = answers._.shift();
94
- }
95
- // now run the filter command if on any questions
96
- questions.filter(function (q) { return q.hasOwnProperty('filter') && typeof q.filter === 'function'; }).forEach(function (question) {
97
- if (answers.hasOwnProperty(question.name)) {
98
- answers[question.name] = question.filter(answers[question.name]);
99
- }
100
- });
101
- return answers;
102
- };
103
- exports.prompt = function (questions, answers) { return __awaiter(_this, void 0, void 0, function () {
104
- var result;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- exports._filter(questions, answers);
109
- return [4 /*yield*/, inquirer.prompt(exports.names(exports.required(exports.filter(questions, answers))))];
110
- case 1:
111
- result = _a.sent();
112
- return [2 /*return*/, __assign({}, result, answers)];
113
- }
114
- });
115
- }); };
116
- });
117
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA,iBAsFA;;IArFA,kBAAgB;IAChB,mCAAqC;IACrC,QAAQ,CAAC,cAAc,CACrB,cAAc,EACd,OAAO,CAAC,8BAA8B,CAAC,CACxC,CAAC;IAUW,QAAA,QAAQ,GAAG,UAAC,SAAkC;QACzD,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,UAAA,CAAC;YACpB,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC9B,CAAC,CAAC,QAAQ,GAAG,UAAC,KAAU;oBACtB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;wBACX,MAAM,CAAI,CAAC,CAAC,IAAI,iBAAc,CAAC;oBACjC,CAAC;oBACD,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;YACD,MAAM,CAAC,CA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AAC,MAAM,CAClC,aAAK,CAAC,gBAAQ,CAAC,cAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAC5C,EAAA;;oBAFK,MAAM,GAAG,SAEd;oBAED,mCACK,MAAM,EACN,OAAO,GACV;;;SACH,CAAC"}
@@ -1,331 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- return new (P || (P = Promise))(function (resolve, reject) {
3
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6
- step((generator = generator.apply(thisArg, _arguments || [])).next());
7
- });
8
- };
9
- var __generator = (this && this.__generator) || function (thisArg, body) {
10
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
11
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
- function verb(n) { return function (v) { return step([n, v]); }; }
13
- function step(op) {
14
- if (f) throw new TypeError("Generator is already executing.");
15
- while (_) try {
16
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
17
- if (y = 0, t) op = [0, t.value];
18
- switch (op[0]) {
19
- case 0: case 1: t = op; break;
20
- case 4: _.label++; return { value: op[1], done: false };
21
- case 5: _.label++; y = op[1]; op = [0]; continue;
22
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
23
- default:
24
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
25
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
27
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28
- if (t[2]) _.ops.pop();
29
- _.trys.pop(); continue;
30
- }
31
- op = body.call(thisArg, _);
32
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
33
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
34
- }
35
- };
36
- (function (factory) {
37
- if (typeof module === "object" && typeof module.exports === "object") {
38
- var v = factory(require, exports);
39
- if (v !== undefined) module.exports = v;
40
- }
41
- else if (typeof define === "function" && define.amd) {
42
- define(["require", "exports", "../index"], factory);
43
- }
44
- })(function (require, exports) {
45
- "use strict";
46
- var _this = this;
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- var index_1 = require("../index");
49
- describe('arguments', function () {
50
- it('empty when all args supplied', function () {
51
- var questions = [
52
- {
53
- name: 'hello',
54
- message: 'hello',
55
- },
56
- {
57
- name: 'world',
58
- message: 'world',
59
- },
60
- ];
61
- var argv = {
62
- hello: 1,
63
- world: 2,
64
- };
65
- expect(index_1.filter(questions, argv)).toEqual([]);
66
- expect(argv).toEqual({
67
- hello: 1,
68
- world: 2,
69
- });
70
- });
71
- it('empty when all args supplied II', function () {
72
- var questions = [
73
- {
74
- _: true,
75
- name: 'foo',
76
- message: 'foo',
77
- },
78
- {
79
- name: 'bar',
80
- message: 'bar',
81
- },
82
- {
83
- _: true,
84
- name: 'baz',
85
- message: 'baz',
86
- },
87
- ];
88
- var argv = {
89
- _: [1, 3],
90
- bar: 2,
91
- };
92
- var _1 = index_1.filter(questions, argv);
93
- var _2 = index_1._filter(questions, argv);
94
- expect(_2).toEqual({ _: [], bar: 2, baz: 3, foo: 1 });
95
- expect(argv).toEqual({
96
- _: [],
97
- foo: 1,
98
- bar: 2,
99
- baz: 3,
100
- });
101
- });
102
- it('init example', function () { return __awaiter(_this, void 0, void 0, function () {
103
- var questions, argv, _1, _2;
104
- return __generator(this, function (_a) {
105
- questions = [
106
- {
107
- _: true,
108
- name: 'foo',
109
- message: '',
110
- },
111
- ];
112
- argv = {
113
- _: [],
114
- bar: 2,
115
- };
116
- _1 = index_1._filter(questions, argv);
117
- _2 = index_1.filter(questions, argv);
118
- expect(_2).toEqual([
119
- {
120
- _: true,
121
- name: 'foo',
122
- message: '',
123
- },
124
- ]);
125
- expect(argv).toEqual({
126
- _: [],
127
- bar: 2,
128
- });
129
- return [2 /*return*/];
130
- });
131
- }); });
132
- it('basic example', function () { return __awaiter(_this, void 0, void 0, function () {
133
- var questions, argv, _2;
134
- return __generator(this, function (_a) {
135
- questions = [
136
- {
137
- name: 'name',
138
- message: 'project name (e.g., flipr)',
139
- required: true,
140
- },
141
- ];
142
- argv = { _: [], cmd: 'init' };
143
- index_1._filter(questions, argv);
144
- _2 = index_1.filter(questions, argv);
145
- expect(_2).toEqual([
146
- {
147
- name: 'name',
148
- message: 'project name (e.g., flipr)',
149
- required: true,
150
- },
151
- ]);
152
- expect(argv).toEqual({ _: [], cmd: 'init' });
153
- return [2 /*return*/];
154
- });
155
- }); });
156
- });
157
- describe('prompt', function () {
158
- it('empty when all args supplied', function () { return __awaiter(_this, void 0, void 0, function () {
159
- var questions, argv, value;
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0:
163
- questions = [
164
- {
165
- name: 'hello',
166
- message: '',
167
- },
168
- {
169
- name: 'world',
170
- message: '',
171
- },
172
- ];
173
- argv = {
174
- hello: 1,
175
- world: 2,
176
- };
177
- return [4 /*yield*/, index_1.prompt(questions, argv)];
178
- case 1:
179
- value = _a.sent();
180
- expect(value).toEqual({
181
- hello: 1,
182
- world: 2,
183
- });
184
- return [2 /*return*/];
185
- }
186
- });
187
- }); });
188
- it('empty when all args supplied', function () { return __awaiter(_this, void 0, void 0, function () {
189
- var questions, argv, value;
190
- return __generator(this, function (_a) {
191
- switch (_a.label) {
192
- case 0:
193
- questions = [
194
- {
195
- _: true,
196
- name: 'foo',
197
- message: '',
198
- },
199
- {
200
- name: 'bar',
201
- message: '',
202
- },
203
- {
204
- _: true,
205
- name: 'baz',
206
- message: '',
207
- },
208
- ];
209
- argv = {
210
- _: [1, 3],
211
- bar: 2,
212
- };
213
- return [4 /*yield*/, index_1.prompt(questions, argv)];
214
- case 1:
215
- value = _a.sent();
216
- expect(argv).toEqual({
217
- _: [],
218
- foo: 1,
219
- bar: 2,
220
- baz: 3,
221
- });
222
- expect(value).toEqual({
223
- _: [],
224
- foo: 1,
225
- bar: 2,
226
- baz: 3,
227
- });
228
- return [2 /*return*/];
229
- }
230
- });
231
- }); });
232
- it('basic example', function () { return __awaiter(_this, void 0, void 0, function () {
233
- var questions, argv, value;
234
- return __generator(this, function (_a) {
235
- switch (_a.label) {
236
- case 0:
237
- questions = [
238
- {
239
- name: 'cmd',
240
- message: 'project name (e.g., flipr)',
241
- required: true,
242
- },
243
- ];
244
- argv = { _: [], cmd: 'init' };
245
- return [4 /*yield*/, index_1.prompt(questions, argv)];
246
- case 1:
247
- value = _a.sent();
248
- expect(value).toEqual(argv);
249
- return [2 /*return*/];
250
- }
251
- });
252
- }); });
253
- });
254
- describe('filter', function () {
255
- it('runs filter without _', function () { return __awaiter(_this, void 0, void 0, function () {
256
- var questions, argv, value;
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0:
260
- questions = [
261
- {
262
- name: 'hello',
263
- message: '',
264
- filter: function (val) {
265
- return val + '!';
266
- }
267
- },
268
- {
269
- name: 'world',
270
- message: '',
271
- filter: function (val) {
272
- return val + '!';
273
- }
274
- },
275
- ];
276
- argv = {
277
- hello: 1,
278
- world: 2,
279
- };
280
- return [4 /*yield*/, index_1.prompt(questions, argv)];
281
- case 1:
282
- value = _a.sent();
283
- expect(value).toEqual({
284
- hello: '1!',
285
- world: '2!',
286
- });
287
- return [2 /*return*/];
288
- }
289
- });
290
- }); });
291
- it('runs filter with _', function () { return __awaiter(_this, void 0, void 0, function () {
292
- var questions, argv, value;
293
- return __generator(this, function (_a) {
294
- switch (_a.label) {
295
- case 0:
296
- questions = [
297
- {
298
- _: true,
299
- name: 'hello',
300
- message: '',
301
- filter: function (val) {
302
- return val + '!';
303
- }
304
- },
305
- {
306
- name: 'world',
307
- message: '',
308
- filter: function (val) {
309
- return val + '!';
310
- }
311
- },
312
- ];
313
- argv = {
314
- _: [1],
315
- world: 2,
316
- };
317
- return [4 /*yield*/, index_1.prompt(questions, argv)];
318
- case 1:
319
- value = _a.sent();
320
- expect(value).toEqual({
321
- _: [],
322
- hello: '1!',
323
- world: '2!',
324
- });
325
- return [2 /*return*/];
326
- }
327
- });
328
- }); });
329
- });
330
- });
331
- //# sourceMappingURL=prompt.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.test.js","sourceRoot":"","sources":["../../test/prompt.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA,iBA4OA;;IA5OA,kCAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE;QACpB,EAAE,CAAC,8BAA8B,EAAE;YACjC,IAAM,SAAS,GAAG;gBAChB;oBACE,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,OAAO;iBACjB;gBACD;oBACE,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,OAAO;iBACjB;aACF,CAAC;YACF,IAAM,IAAI,GAAG;gBACX,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;aACT,CAAC;YACF,MAAM,CAAC,cAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBACnB,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,iCAAiC,EAAE;YACpC,IAAM,SAAS,GAAG;gBAChB;oBACE,CAAC,EAAE,IAAI;oBACP,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,KAAK;iBACf;gB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I,GAAG;4BACX,CAAC,EAAE,CAAC,CAAC,CAAC;4BACN,KAAK,EAAE,CAAC;yBACT,CAAC;wBAEY,qBAAM,cAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAA;;wBAArC,KAAK,GAAG,SAA6B;wBAC3C,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;4BACpB,CAAC,EAAE,EAAE;4BACL,KAAK,EAAE,IAAI;4BACX,KAAK,EAAE,IAAI;yBACZ,CAAC,CAAC;;;;aACJ,CAAC,CAAC;IACL,CAAC,CAAC,CAAA"}
@@ -1,21 +0,0 @@
1
- import 'colors';
2
- export interface InquirerQuestion {
3
- _?: boolean;
4
- name: string;
5
- message: string;
6
- required?: boolean;
7
- validate?: Function;
8
- }
9
- export declare const required: (questions: InquirerQuestion[]) => InquirerQuestion[];
10
- export declare const names: (questions: InquirerQuestion[]) => InquirerQuestion[];
11
- export declare const filter: (questions: InquirerQuestion[], answers: {
12
- [type: string]: any;
13
- }) => (InquirerQuestion | undefined)[];
14
- export declare const _filter: (questions: InquirerQuestion[], answers: {
15
- [type: string]: any;
16
- }) => {
17
- [type: string]: any;
18
- };
19
- export declare const prompt: (questions: InquirerQuestion[], answers: {
20
- [type: string]: any;
21
- }) => Promise<any>;
package/index.ts DELETED
@@ -1,86 +0,0 @@
1
- import { exec } from 'child_process';
2
- import 'colors';
3
- import * as inquirer from 'inquirer';
4
- inquirer.registerPrompt(
5
- 'autocomplete',
6
- require('inquirer-autocomplete-prompt')
7
- );
8
-
9
- export interface InquirerQuestion {
10
- _?: boolean;
11
- name: string;
12
- message: string;
13
- required?: boolean;
14
- validate?: Function;
15
- }
16
-
17
- export const required = (questions: Array<InquirerQuestion>) => {
18
- return questions.map(q => {
19
- if (q.required && !q.validate) {
20
- q.validate = (value: any) => {
21
- if (!value) {
22
- return `${q.name} is required`;
23
- }
24
- return true;
25
- };
26
- }
27
- return q;
28
- });
29
- };
30
-
31
- export const names = (questions: Array<InquirerQuestion>) => {
32
- return questions.map(q => {
33
- q.message = `${'['.white}${q.name.blue}${']'.white} ${q.message.green}`;
34
- return q;
35
- });
36
- };
37
-
38
- export const filter = (
39
- questions: Array<InquirerQuestion>,
40
- answers: { [type: string]: any }
41
- ) => {
42
- const A = questions.map(q => q.name);
43
- const B = Object.keys(answers);
44
- const diff = A.filter(x => !B.includes(x));
45
- return A.filter(n => diff.includes(n)).map(name =>
46
- questions.find(o => o.name === name)
47
- );
48
- };
49
-
50
- // converts argv._ into the answers when question specifies it
51
- export const _filter = (
52
- questions: Array<InquirerQuestion>,
53
- answers: { [type: string]: any }
54
- ) => {
55
- const _Qs = questions.filter(q => q.hasOwnProperty('_'));
56
- const A = _Qs.map((v, i) => i + '');
57
- const B = Object.keys(answers._ || []);
58
- var includes = A.filter(x => B.includes(x));
59
- for (var i = 0; i < includes.length; i++) {
60
- answers[_Qs[i].name] = answers._.shift();
61
- }
62
-
63
- // now run the filter command if on any questions
64
- questions.filter(q => q.hasOwnProperty('filter') && typeof q.filter === 'function' ).forEach(question=> {
65
- if (answers.hasOwnProperty(question.name)) {
66
- answers[question.name] = question.filter(answers[question.name]);
67
- }
68
- });
69
-
70
- return answers;
71
- };
72
-
73
- export const prompt = async (
74
- questions: Array<InquirerQuestion>,
75
- answers: { [type: string]: any }
76
- ) => {
77
- _filter(questions, answers);
78
- const result = await inquirer.prompt(
79
- names(required(filter(questions, answers)))
80
- );
81
-
82
- return {
83
- ...result,
84
- ...answers,
85
- };
86
- };
package/readme.md DELETED
@@ -1,105 +0,0 @@
1
- # Inquirerer
2
-
3
- ```sh
4
- npm install inquirerer
5
- ```
6
-
7
- A wrapper around Inquirer to solve this issue: https://github.com/SBoudrias/Inquirer.js/issues/166
8
-
9
- Allows you to override properties passed in, and won't be asked interactively. This is huge when creating real production systems where scripts need to run automatically without human interaction.
10
-
11
- ## override properties
12
-
13
- Imagine this exists in a file `myprogram.js`:
14
-
15
- ```js
16
- import { prompt } from 'inquirer';
17
- var argv = require('minimist')(process.argv.slice(2));
18
-
19
- const questions = [
20
- {
21
- name: 'database',
22
- message: 'database',
23
- required: true,
24
- ...
25
- },
26
- ];
27
-
28
- const { database } = await prompt(questions, argv);
29
- ```
30
-
31
- To run interactively, just run `node myprogram.js`. However, if you want to override, simply do:
32
-
33
- ```sh
34
- node myprogram.js --database mydb1
35
- ```
36
-
37
- And will skip the interactive phase, unless more questions are unanswered.
38
-
39
- ## `_` properties
40
-
41
- If you set `_: true`, then you can pass an argument into the system and it won't need the parameter name.
42
-
43
- ```js
44
- const questions = [
45
- {
46
- _: true,
47
- name: 'database',
48
- message: 'database',
49
- required: true,
50
- ...
51
- },
52
- ];
53
-
54
- const { database } = await prompt(questions, argv);
55
- ```
56
-
57
- Now you can run with or without the `--database` flag
58
-
59
- ```sh
60
- node myprogram.js mydb1
61
- ```
62
-
63
- or equivalently:
64
-
65
- ```sh
66
- node myprogram.js --database mydb1
67
- ```
68
-
69
- ## `_` properties with multiple
70
-
71
- ```
72
- const questions = [
73
- {
74
- _: true,
75
- name: 'foo',
76
- message: 'foo',
77
- },
78
- {
79
- name: 'bar',
80
- message: 'bar',
81
- },
82
- {
83
- _: true,
84
- name: 'baz',
85
- message: 'baz',
86
- },
87
- ];
88
-
89
- const result = await prompt(questions, argv);
90
- ```
91
-
92
- ```sh
93
- node myprogram.js 1 3 --bar 2
94
- ```
95
-
96
- will treat `argv` as
97
-
98
- ```
99
- {
100
- _: [],
101
- foo: 1,
102
- bar: 2,
103
- baz: 3,
104
- }
105
- ```