From 8bdc089de48b6e5ae1c4083e5edda8bab437bb75 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 25 Apr 2016 15:47:05 -0400 Subject: [PATCH] Implement validation support in Etcher CLI (#361) Signed-off-by: Juan Cruz Viotti --- lib/cli/cli.js | 7 +++++++ lib/cli/etcher.js | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index b76b066c..40f02b3b 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -41,6 +41,7 @@ module.exports = yargs // Examples .example('$0 raspberry-pi.img') + .example('$0 --no-check raspberry-pi.img') .example('$0 -d /dev/disk2 ubuntu.iso') .example('$0 -d /dev/disk2 -y rpi.img') @@ -87,6 +88,12 @@ module.exports = yargs string: true, alias: 'd' }, + check: { + describe: 'validate write', + boolean: true, + alias: 'c', + default: true + }, robot: { describe: 'parse-able output without interactivity', boolean: true, diff --git a/lib/cli/etcher.js b/lib/cli/etcher.js index 081e1046..599f0f7d 100644 --- a/lib/cli/etcher.js +++ b/lib/cli/etcher.js @@ -49,13 +49,16 @@ form.run([ throw new Error('Aborted'); } - const progressBar = new visuals.Progress('Burning'); + const progressBars = { + write: new visuals.Progress('Flashing'), + check: new visuals.Progress('Validating') + }; return writer.writeImage(options._[0], { device: answers.drive }, { unmountOnSuccess: false, - validateWriteOnSuccess: false + validateWriteOnSuccess: options.check }, function(state) { if (options.robot) { @@ -66,16 +69,20 @@ form.run([ Math.floor(state.speed) ].join(' ')); } else { - progressBar.update(state); + progressBars[state.type].update(state); } }); -}).then(function() { +}).then(function(success) { if (options.robot) { - console.log('done'); - } else { + return console.log(`done ${success}`); + } + + if (success) { console.log('Your flash is complete!'); + } else { + console.error('Validation failed!'); } }).catch(function(error) {