diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 677cbf56..b76b066c 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -63,6 +63,14 @@ module.exports = yargs return true; }) + .check(function(argv) { + if (argv.robot && !argv.drive) { + throw new Error('Missing drive'); + } + + return true; + }) + .options({ help: { describe: 'show help', @@ -79,6 +87,11 @@ module.exports = yargs string: true, alias: 'd' }, + robot: { + describe: 'parse-able output without interactivity', + boolean: true, + alias: 'r' + }, yes: { describe: 'confirm non-interactively', boolean: true, diff --git a/lib/cli/etcher.js b/lib/cli/etcher.js index 4b4034e7..081e1046 100644 --- a/lib/cli/etcher.js +++ b/lib/cli/etcher.js @@ -41,7 +41,7 @@ form.run([ // If `options.yes` is `false`, pass `undefined`, // otherwise the question will not be asked because // `false` is a defined value. - yes: options.yes || undefined + yes: options.robot || options.yes || undefined } }).then(function(answers) { @@ -49,7 +49,7 @@ form.run([ throw new Error('Aborted'); } - var progressBar = new visuals.Progress('Burning'); + const progressBar = new visuals.Progress('Burning'); return writer.writeImage(options._[0], { device: answers.drive @@ -57,11 +57,34 @@ form.run([ unmountOnSuccess: false, validateWriteOnSuccess: false }, function(state) { - return progressBar.update(state); + + if (options.robot) { + console.log([ + state.type, + Math.floor(state.percentage) + '%', + state.eta + 's', + Math.floor(state.speed) + ].join(' ')); + } else { + progressBar.update(state); + } + }); }).then(function() { - console.log('Your flash is complete!'); + + if (options.robot) { + console.log('done'); + } else { + console.log('Your flash is complete!'); + } + }).catch(function(error) { - utils.printError(error); + + if (options.robot) { + console.error(error.message); + } else { + utils.printError(error); + } + process.exit(1); });