feat(CLI): validate drive (#587)

The Etcher CLI doesn't care if the drive exists or not. The user will
eventually find out since the CLI will output an `ENOENT` when trying to
actually write data, however its nicer from a UX perspective to catch
this early on.

Change-Type: minor
Changelog-Entry: Validate the existence of the passed drive.
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-07-21 18:31:08 -04:00 committed by GitHub
parent d2a8739904
commit 5f943e98be

View File

@ -16,8 +16,11 @@
'use strict';
const _ = require('lodash');
const Bluebird = require('bluebird');
const visuals = require('resin-cli-visuals');
const form = require('resin-cli-form');
const drivelist = Bluebird.promisifyAll(require('drivelist'));
const writer = require('./writer');
const utils = require('./utils');
const options = require('./cli');
@ -56,9 +59,16 @@ form.run([
check: new visuals.Progress('Validating')
};
return writer.writeImage(options._[0], {
return drivelist.listAsync().then((drives) => {
const selectedDrive = _.find(drives, {
device: answers.drive
}, {
});
if (!selectedDrive) {
throw new Error(`Drive not found: ${selectedDrive}`);
}
return writer.writeImage(options._[0], selectedDrive, {
unmountOnSuccess: options.unmount,
validateWriteOnSuccess: options.check
}, (state) => {
@ -78,6 +88,7 @@ form.run([
}
});
});
}).then((results) => {
if (options.robot) {