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
.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,

View File

@ -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) {