mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-16 07:46:31 +00:00
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:
parent
d2a8739904
commit
5f943e98be
@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
|
const Bluebird = require('bluebird');
|
||||||
const visuals = require('resin-cli-visuals');
|
const visuals = require('resin-cli-visuals');
|
||||||
const form = require('resin-cli-form');
|
const form = require('resin-cli-form');
|
||||||
|
const drivelist = Bluebird.promisifyAll(require('drivelist'));
|
||||||
const writer = require('./writer');
|
const writer = require('./writer');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const options = require('./cli');
|
const options = require('./cli');
|
||||||
@ -56,27 +59,35 @@ form.run([
|
|||||||
check: new visuals.Progress('Validating')
|
check: new visuals.Progress('Validating')
|
||||||
};
|
};
|
||||||
|
|
||||||
return writer.writeImage(options._[0], {
|
return drivelist.listAsync().then((drives) => {
|
||||||
device: answers.drive
|
const selectedDrive = _.find(drives, {
|
||||||
}, {
|
device: answers.drive
|
||||||
unmountOnSuccess: options.unmount,
|
});
|
||||||
validateWriteOnSuccess: options.check
|
|
||||||
}, (state) => {
|
|
||||||
|
|
||||||
if (options.robot) {
|
if (!selectedDrive) {
|
||||||
log.toStdout(JSON.stringify({
|
throw new Error(`Drive not found: ${selectedDrive}`);
|
||||||
command: 'progress',
|
|
||||||
data: {
|
|
||||||
type: state.type,
|
|
||||||
percentage: Math.floor(state.percentage),
|
|
||||||
eta: state.eta,
|
|
||||||
speed: Math.floor(state.speed)
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
progressBars[state.type].update(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return writer.writeImage(options._[0], selectedDrive, {
|
||||||
|
unmountOnSuccess: options.unmount,
|
||||||
|
validateWriteOnSuccess: options.check
|
||||||
|
}, (state) => {
|
||||||
|
|
||||||
|
if (options.robot) {
|
||||||
|
log.toStdout(JSON.stringify({
|
||||||
|
command: 'progress',
|
||||||
|
data: {
|
||||||
|
type: state.type,
|
||||||
|
percentage: Math.floor(state.percentage),
|
||||||
|
eta: state.eta,
|
||||||
|
speed: Math.floor(state.speed)
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
progressBars[state.type].update(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}).then((results) => {
|
}).then((results) => {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user