mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
f2bd3c0ffb
Change-type: patch Signed-off-by: Gergely Imreh <gergely@balena.io>
36 lines
943 B
TypeScript
36 lines
943 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 != null
|
|
? `${(drive.size / 1e9).toFixed(1).toString()} GB`
|
|
: 'Unknown size';
|
|
return `${drive.device} (${size}) - ${drive.description}`;
|
|
}
|
|
}
|