(argv: ArgumentsCamelCase<CommandArgs>)
| 34 | .epilog(buildEpilog({ command, apiDocs: 'uninstallDriver' })) |
| 35 | |
| 36 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 37 | const command = await apiCommand(argv) |
| 38 | |
| 39 | const hubId = await chooseHub( |
| 40 | command, |
| 41 | argv.hub, |
| 42 | { promptMessage: 'Select a hub to prune drivers on.', useConfigDefault: true }, |
| 43 | ) |
| 44 | |
| 45 | const installedDrivers = await command.client.hubdevices.listInstalled(hubId) |
| 46 | const isDefined = (item?: string): item is string => item != null |
| 47 | const inUseDriverIds = (await getDriverDevices(command.client)) |
| 48 | .map(info => info.driverId) |
| 49 | .filter(isDefined) |
| 50 | .flat() |
| 51 | |
| 52 | // LAN drivers can be automatically re-installed so we don't allow pruning them. |
| 53 | // no ocean currents here :-) |
| 54 | const defaultLANDrivers = (await command.client.drivers.listDefault()) |
| 55 | .filter(driver => driver.permissions?.find(permission => permission.name === 'lan')) |
| 56 | .map(driver => driver.driverId) |
| 57 | const prunableDrivers = installedDrivers |
| 58 | .filter(driver => !inUseDriverIds.includes(driver.driverId)) |
| 59 | .filter(driver => !defaultLANDrivers.includes(driver.driverId)) |
| 60 | |
| 61 | if (prunableDrivers.length === 0) { |
| 62 | console.log('No unused drivers found.') |
| 63 | } else { |
| 64 | console.log(`Found ${prunableDrivers.length} unused drivers.`) |
| 65 | const config: FormatAndWriteItemConfig<InstalledDriver> = { |
| 66 | tableFieldDefinitions: [ |
| 67 | 'driverId', |
| 68 | 'name', |
| 69 | { prop: 'description', skipEmpty: true }, |
| 70 | 'version', |
| 71 | 'channelId', |
| 72 | 'developer', |
| 73 | { prop: 'vendorSupportInformation', skipEmpty: true }, |
| 74 | ], |
| 75 | } |
| 76 | for (const prunableDriver of prunableDrivers) { |
| 77 | console.log('\n\nFound unused driver:') |
| 78 | await formatAndWriteItem(command, config, prunableDriver) |
| 79 | const doUninstall = await booleanInput(`Uninstall ${prunableDriver.name} driver?`, { default: false }) |
| 80 | if (doUninstall) { |
| 81 | await command.client.hubdevices.uninstallDriver(prunableDriver.driverId, hubId) |
| 82 | console.log(`Driver ${prunableDriver.driverId} uninstalled from hub ${hubId}.`) |
| 83 | } else { |
| 84 | console.log(`Left driver ${prunableDriver.name} installed.`) |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 91 | export default cmd |
nothing calls this directly
no test coverage detected