mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-30 02:28:51 +00:00
32 lines
822 B
TypeScript
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}`;
|
||
|
}
|
||
|
}
|