diff --git a/__tests__/commands/__snapshots__/run.js.snap b/__tests__/commands/__snapshots__/run.js.snap index 0b22fa9b6d..2fa7a6139e 100644 --- a/__tests__/commands/__snapshots__/run.js.snap +++ b/__tests__/commands/__snapshots__/run.js.snap @@ -2,11 +2,6 @@ exports[`returns noBinAvailable with no bins 1`] = ` Array [ - Object { - "data": "No command specified.", - "error": true, - "type": "error", - }, Object { "data": "There are no binary scripts available.", "error": true, @@ -44,11 +39,6 @@ Array [ exports[`returns noScriptsAvailable with no scripts 1`] = ` Array [ - Object { - "data": "No command specified.", - "error": true, - "type": "error", - }, Object { "data": "Commands available from binary scripts: cat-names", "error": false, diff --git a/__tests__/commands/run.js b/__tests__/commands/run.js index 085441ebcc..2bad11ef51 100644 --- a/__tests__/commands/run.js +++ b/__tests__/commands/run.js @@ -62,7 +62,6 @@ test('lists all available commands with no arguments', (): Promise => const bins = ['cat-names']; // Emulate run output - rprtr.error(rprtr.lang('commandNotSpecified')); rprtr.info(`${rprtr.lang('binCommands')}${bins.join(', ')}`); rprtr.info(rprtr.lang('possibleCommands')); rprtr.list('possibleCommands', scripts, hints); @@ -71,6 +70,25 @@ test('lists all available commands with no arguments', (): Promise => expect(reporter.getBuffer()).toEqual(rprtr.getBuffer()); })); +test('lists all available commands with no arguments and --non-interactive', (): Promise => + runRun([], {nonInteractive: true}, 'no-args', (config, reporter): ?Promise => { + const rprtr = new reporters.BufferReporter({stdout: null, stdin: null}); + const scripts = ['build', 'prestart', 'start']; + const hints = { + build: "echo 'building'", + prestart: "echo 'prestart'", + start: 'node index.js', + }; + const bins = ['cat-names']; + + // Emulate run output + rprtr.info(`${rprtr.lang('binCommands')}${bins.join(', ')}`); + rprtr.info(rprtr.lang('possibleCommands')); + rprtr.list('possibleCommands', scripts, hints); + + expect(reporter.getBuffer()).toEqual(rprtr.getBuffer()); + })); + test('runs script containing spaces', (): Promise => runRun(['build'], {}, 'spaces', async (config): ?Promise => { const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); diff --git a/src/cli/commands/run.js b/src/cli/commands/run.js index a7b2dbd19a..30b62d61b5 100644 --- a/src/cli/commands/run.js +++ b/src/cli/commands/run.js @@ -113,8 +113,6 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg // list possible scripts if none specified if (args.length === 0) { - reporter.error(reporter.lang('commandNotSpecified')); - if (binCommands.length) { reporter.info(`${reporter.lang('binCommands') + binCommands.join(', ')}`); } else { @@ -124,12 +122,14 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg if (pkgCommands.length) { reporter.info(`${reporter.lang('possibleCommands')}`); reporter.list('possibleCommands', pkgCommands, cmdHints); - await reporter - .question(reporter.lang('commandQuestion')) - .then( - answer => runCommand(answer.trim().split(' ')), - () => reporter.error(reporter.lang('commandNotSpecified')), - ); + if (!flags.nonInteractive) { + await reporter + .question(reporter.lang('commandQuestion')) + .then( + answer => runCommand(answer.trim().split(' ')), + () => reporter.error(reporter.lang('commandNotSpecified')), + ); + } } else { reporter.error(reporter.lang('noScriptsAvailable')); }