Implement validation support in Etcher CLI (#361)

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-04-25 15:47:05 -04:00
parent 86cbff940c
commit 8bdc089de4
2 changed files with 20 additions and 6 deletions

View File

@ -41,6 +41,7 @@ module.exports = yargs
// Examples // Examples
.example('$0 raspberry-pi.img') .example('$0 raspberry-pi.img')
.example('$0 --no-check raspberry-pi.img')
.example('$0 -d /dev/disk2 ubuntu.iso') .example('$0 -d /dev/disk2 ubuntu.iso')
.example('$0 -d /dev/disk2 -y rpi.img') .example('$0 -d /dev/disk2 -y rpi.img')
@ -87,6 +88,12 @@ module.exports = yargs
string: true, string: true,
alias: 'd' alias: 'd'
}, },
check: {
describe: 'validate write',
boolean: true,
alias: 'c',
default: true
},
robot: { robot: {
describe: 'parse-able output without interactivity', describe: 'parse-able output without interactivity',
boolean: true, boolean: true,

View File

@ -49,13 +49,16 @@ form.run([
throw new Error('Aborted'); 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], { return writer.writeImage(options._[0], {
device: answers.drive device: answers.drive
}, { }, {
unmountOnSuccess: false, unmountOnSuccess: false,
validateWriteOnSuccess: false validateWriteOnSuccess: options.check
}, function(state) { }, function(state) {
if (options.robot) { if (options.robot) {
@ -66,16 +69,20 @@ form.run([
Math.floor(state.speed) Math.floor(state.speed)
].join(' ')); ].join(' '));
} else { } else {
progressBar.update(state); progressBars[state.type].update(state);
} }
}); });
}).then(function() { }).then(function(success) {
if (options.robot) { if (options.robot) {
console.log('done'); return console.log(`done ${success}`);
} else { }
if (success) {
console.log('Your flash is complete!'); console.log('Your flash is complete!');
} else {
console.error('Validation failed!');
} }
}).catch(function(error) { }).catch(function(error) {