inquirerer 0.5.0 → 0.7.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/commander.d.ts +2 -2
- package/commander.js +10 -5
- package/esm/commander.js +10 -5
- package/esm/prompt.js +13 -1
- package/package.json +2 -2
- package/prompt.d.ts +9 -2
- package/prompt.js +13 -1
package/commander.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class CLI {
|
|
|
16
16
|
private prompter;
|
|
17
17
|
private commandHandler;
|
|
18
18
|
private options;
|
|
19
|
-
constructor(commandHandler: CommandHandler, options: Partial<CLIOptions
|
|
20
|
-
run(): void
|
|
19
|
+
constructor(commandHandler: CommandHandler, options: Partial<CLIOptions>, argv?: any);
|
|
20
|
+
run(): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
export default CLI;
|
package/commander.js
CHANGED
|
@@ -24,18 +24,22 @@ class CLI {
|
|
|
24
24
|
prompter;
|
|
25
25
|
commandHandler;
|
|
26
26
|
options;
|
|
27
|
-
constructor(commandHandler, options) {
|
|
27
|
+
constructor(commandHandler, options, argv) {
|
|
28
28
|
const { input, output, ...optionsWithoutIO } = options;
|
|
29
29
|
const { input: defaultInput, output: defaultOutput, ...defaultOptionsWithoutIO } = exports.defaultCLIOptions;
|
|
30
30
|
const mergedOptions = (0, deepmerge_1.default)(defaultOptionsWithoutIO, optionsWithoutIO);
|
|
31
31
|
mergedOptions.input = input || defaultInput;
|
|
32
32
|
mergedOptions.output = output || defaultOutput;
|
|
33
33
|
this.options = mergedOptions;
|
|
34
|
-
this.argv = (0, minimist_1.default)(process.argv.slice(2), this.options.minimistOpts);
|
|
35
|
-
this.prompter = new prompt_1.Inquirerer(
|
|
34
|
+
this.argv = argv ? argv : (0, minimist_1.default)(process.argv.slice(2), this.options.minimistOpts);
|
|
35
|
+
this.prompter = new prompt_1.Inquirerer({
|
|
36
|
+
noTty: this.options.noTty,
|
|
37
|
+
input: this.options.input,
|
|
38
|
+
output: this.options.output
|
|
39
|
+
});
|
|
36
40
|
this.commandHandler = commandHandler;
|
|
37
41
|
}
|
|
38
|
-
run() {
|
|
42
|
+
async run() {
|
|
39
43
|
if (!('tty' in this.argv)) {
|
|
40
44
|
this.argv.tty = true;
|
|
41
45
|
}
|
|
@@ -43,8 +47,9 @@ class CLI {
|
|
|
43
47
|
console.log(this.options.version);
|
|
44
48
|
process.exit(0);
|
|
45
49
|
}
|
|
46
|
-
this.commandHandler(this.argv, this.prompter, this.options);
|
|
50
|
+
const args = await this.commandHandler(this.argv, this.prompter, this.options);
|
|
47
51
|
this.prompter.close();
|
|
52
|
+
return args;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
exports.CLI = CLI;
|
package/esm/commander.js
CHANGED
|
@@ -18,18 +18,22 @@ export class CLI {
|
|
|
18
18
|
prompter;
|
|
19
19
|
commandHandler;
|
|
20
20
|
options;
|
|
21
|
-
constructor(commandHandler, options) {
|
|
21
|
+
constructor(commandHandler, options, argv) {
|
|
22
22
|
const { input, output, ...optionsWithoutIO } = options;
|
|
23
23
|
const { input: defaultInput, output: defaultOutput, ...defaultOptionsWithoutIO } = defaultCLIOptions;
|
|
24
24
|
const mergedOptions = deepmerge(defaultOptionsWithoutIO, optionsWithoutIO);
|
|
25
25
|
mergedOptions.input = input || defaultInput;
|
|
26
26
|
mergedOptions.output = output || defaultOutput;
|
|
27
27
|
this.options = mergedOptions;
|
|
28
|
-
this.argv = minimist(process.argv.slice(2), this.options.minimistOpts);
|
|
29
|
-
this.prompter = new Inquirerer(
|
|
28
|
+
this.argv = argv ? argv : minimist(process.argv.slice(2), this.options.minimistOpts);
|
|
29
|
+
this.prompter = new Inquirerer({
|
|
30
|
+
noTty: this.options.noTty,
|
|
31
|
+
input: this.options.input,
|
|
32
|
+
output: this.options.output
|
|
33
|
+
});
|
|
30
34
|
this.commandHandler = commandHandler;
|
|
31
35
|
}
|
|
32
|
-
run() {
|
|
36
|
+
async run() {
|
|
33
37
|
if (!('tty' in this.argv)) {
|
|
34
38
|
this.argv.tty = true;
|
|
35
39
|
}
|
|
@@ -37,8 +41,9 @@ export class CLI {
|
|
|
37
41
|
console.log(this.options.version);
|
|
38
42
|
process.exit(0);
|
|
39
43
|
}
|
|
40
|
-
this.commandHandler(this.argv, this.prompter, this.options);
|
|
44
|
+
const args = await this.commandHandler(this.argv, this.prompter, this.options);
|
|
41
45
|
this.prompter.close();
|
|
46
|
+
return args;
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
export default CLI;
|
package/esm/prompt.js
CHANGED
|
@@ -33,7 +33,10 @@ export class Inquirerer {
|
|
|
33
33
|
keypress;
|
|
34
34
|
noTty;
|
|
35
35
|
output;
|
|
36
|
-
|
|
36
|
+
useDefaults;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false } = options ?? {};
|
|
39
|
+
this.useDefaults = useDefaults;
|
|
37
40
|
this.noTty = noTty;
|
|
38
41
|
this.output = output;
|
|
39
42
|
if (!noTty) {
|
|
@@ -74,6 +77,10 @@ export class Inquirerer {
|
|
|
74
77
|
let numTries = 0;
|
|
75
78
|
while (index < questions.length) {
|
|
76
79
|
const question = questions[index];
|
|
80
|
+
if ('default' in question && this.useDefaults) {
|
|
81
|
+
obj[question.name] = question.default;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
77
84
|
const ctx = {
|
|
78
85
|
numTries
|
|
79
86
|
};
|
|
@@ -100,6 +107,11 @@ export class Inquirerer {
|
|
|
100
107
|
obj[question.name] = undefined;
|
|
101
108
|
continue; // Stay on the same question
|
|
102
109
|
}
|
|
110
|
+
else {
|
|
111
|
+
if ('default' in question) {
|
|
112
|
+
obj[question.name] = question.default;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
103
115
|
}
|
|
104
116
|
index++; // Move to the next question
|
|
105
117
|
numTries = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "inquirerer",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"minimist": "^1.2.8"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "49eaa8d76816d598381eaed418c9a8a276656a52"
|
|
39
39
|
}
|
package/prompt.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Readable, Writable } from 'stream';
|
|
3
3
|
import { AutocompleteQuestion, CheckboxQuestion, ConfirmQuestion, Question, TextQuestion, Value } from './question';
|
|
4
4
|
interface PromptContext {
|
|
5
5
|
numTries: number;
|
|
6
6
|
}
|
|
7
|
+
export interface InquirererOptions {
|
|
8
|
+
noTty?: boolean;
|
|
9
|
+
input?: Readable;
|
|
10
|
+
output?: Writable;
|
|
11
|
+
useDefaults?: boolean;
|
|
12
|
+
}
|
|
7
13
|
export declare class Inquirerer {
|
|
8
14
|
private rl;
|
|
9
15
|
private keypress;
|
|
10
16
|
private noTty;
|
|
11
17
|
private output;
|
|
12
|
-
|
|
18
|
+
private useDefaults;
|
|
19
|
+
constructor(options?: InquirererOptions);
|
|
13
20
|
clearScreen(): void;
|
|
14
21
|
write(message: string): void;
|
|
15
22
|
log(message: string): void;
|
package/prompt.js
CHANGED
|
@@ -39,7 +39,10 @@ class Inquirerer {
|
|
|
39
39
|
keypress;
|
|
40
40
|
noTty;
|
|
41
41
|
output;
|
|
42
|
-
|
|
42
|
+
useDefaults;
|
|
43
|
+
constructor(options) {
|
|
44
|
+
const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false } = options ?? {};
|
|
45
|
+
this.useDefaults = useDefaults;
|
|
43
46
|
this.noTty = noTty;
|
|
44
47
|
this.output = output;
|
|
45
48
|
if (!noTty) {
|
|
@@ -80,6 +83,10 @@ class Inquirerer {
|
|
|
80
83
|
let numTries = 0;
|
|
81
84
|
while (index < questions.length) {
|
|
82
85
|
const question = questions[index];
|
|
86
|
+
if ('default' in question && this.useDefaults) {
|
|
87
|
+
obj[question.name] = question.default;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
83
90
|
const ctx = {
|
|
84
91
|
numTries
|
|
85
92
|
};
|
|
@@ -106,6 +113,11 @@ class Inquirerer {
|
|
|
106
113
|
obj[question.name] = undefined;
|
|
107
114
|
continue; // Stay on the same question
|
|
108
115
|
}
|
|
116
|
+
else {
|
|
117
|
+
if ('default' in question) {
|
|
118
|
+
obj[question.name] = question.default;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
109
121
|
}
|
|
110
122
|
index++; // Move to the next question
|
|
111
123
|
numTries = 0;
|