Merge pull request #1663 from balena-io/fix-local-flash

Fix `balena local flash`
This commit is contained in:
Page- 2020-03-12 22:14:42 +00:00 committed by GitHub
commit 731bd909d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,22 @@ import { getChalk, getVisuals } from '../../utils/lazy';
async function getDrive(options: {
drive?: string;
}): Promise<SDK.sourceDestination.BlockDevice> {
return options.drive || getVisuals().drive('Select a drive');
const drive = options.drive || (await getVisuals().drive('Select a drive'));
const sdk = await import('etcher-sdk');
const adapter = new sdk.scanner.adapters.BlockDeviceAdapter(() => false);
const scanner = new sdk.scanner.Scanner([adapter]);
await scanner.start();
try {
const d = scanner.getBy('device', drive);
if (d === undefined || !(d instanceof sdk.sourceDestination.BlockDevice)) {
throw new Error(`Drive not found: ${options.drive}`);
}
return d;
} finally {
scanner.stop();
}
}
export const flash: CommandDefinition<