balena-cli/lib/utils/visuals/drive-list.ts
Alexis Svinartchouk f9390ceb10 Update lib/actions/local/flash.coffee
* switch to typescript
 * replace etcher-image-stream with etcher-sdk

Change-type: patch
2019-01-11 17:56:34 +01:00

32 lines
822 B
TypeScript

import chalk from 'chalk';
import * as sdk from 'etcher-sdk';
import { CustomDynamicList } from './custom-dynamic-list';
export class DriveList extends CustomDynamicList<
sdk.sourceDestination.BlockDevice
> {
constructor(private scanner: sdk.scanner.Scanner) {
super(
'Select a drive',
`${chalk.red('x')} No available drives were detected, plug one in!`,
);
const refresh = this.refresh.bind(this);
scanner.on('attach', refresh);
scanner.on('detach', refresh);
}
protected *getThings() {
for (const drive of this.scanner.drives) {
if (drive instanceof sdk.sourceDestination.BlockDevice) {
yield drive;
}
}
}
protected format(drive: sdk.sourceDestination.BlockDevice) {
const size = drive.size / 1e9;
return `${drive.device} (${size.toFixed(1)} GB) - ${drive.description}`;
}
}