mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +00:00
ce1aff1557
Change-type: patch
33 lines
876 B
TypeScript
33 lines
876 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() {
|
|
const sdk: typeof _sdk = require('etcher-sdk');
|
|
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}`;
|
|
}
|
|
}
|