Skip to content

Commit e7c6c6a

Browse files
committed
feat(ui): add command line arg to disable prompts
refs #233 - adds a `--no-prompt` global option that will cause ui.prompt to throw - dry up prompt spinner handling code
1 parent bfbf0ae commit e7c6c6a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/bootstrap.js

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ module.exports = {
9595
describe: 'Enable verbose output',
9696
type: 'boolean'
9797
})
98+
.options('prompt', {
99+
describe: 'Disable UI prompting (useful for bash scripting)',
100+
type: 'boolean',
101+
default: true
102+
})
98103
.version()
99104
.help()
100105
.parse(argv);

lib/command.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class Command {
108108
let verbose = argv.verbose;
109109

110110
let ui = new UI({
111-
verbose: verbose
111+
verbose: verbose,
112+
allowPrompt: argv.prompt
112113
});
113114
let service = ServiceManager.load(ui);
114115
let context = {

lib/ui.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const defaultOptions = {
1717
stdin: process.stdin,
1818
stdout: process.stdout,
1919
stderr: process.stderr,
20-
verbose: false
20+
verbose: false,
21+
allowPrompt: true
2122
};
2223

2324
class UI {
@@ -29,6 +30,7 @@ class UI {
2930
this.stdout = this.options.stdout;
3031
this.stderr = this.options.stderr;
3132
this.verbose = this.options.verbose;
33+
this.allowPrompt = this.options.allowPrompt;
3234

3335
// Add custom prompt module that uses the
3436
// specified streams
@@ -68,15 +70,11 @@ class UI {
6870
}
6971

7072
prompt(prompts) {
71-
if (!this.spinner) {
72-
return this.inquirer(prompts);
73+
if (!this.allowPrompt) {
74+
throw new errors.SystemError('Prompts have been disabled, please provide options via command line flags');
7375
}
7476

75-
this.spinner.stop();
76-
return this.inquirer(prompts).then((result) => {
77-
this.spinner.start();
78-
return result;
79-
});
77+
return this.noSpin(() => this.inquirer(prompts));
8078
}
8179

8280
sudo(command, options) {

0 commit comments

Comments
 (0)