(argv: ArgumentsCamelCase<CommandArgs>)
| 51 | .epilog(buildEpilog({ command, apiDocs: ['getDevices', 'listDrivers', 'getDriver', 'getDriverRevision'] })) |
| 52 | |
| 53 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 54 | const command = await apiCommand(argv) |
| 55 | |
| 56 | const config: OutputItemOrListConfig<DeviceDriverInfo> = { |
| 57 | primaryKeyName: 'deviceId', |
| 58 | sortKeyName: 'label', |
| 59 | tableFieldDefinitions: ['label', 'type', 'deviceId', 'driverId', 'hubId', 'hubLabel'], |
| 60 | listTableFieldDefinitions: ['label', 'type', 'deviceId', 'driverId'], |
| 61 | } |
| 62 | |
| 63 | const matchesUserFilters = (device: DeviceDriverInfo): boolean => { |
| 64 | if (argv.hub && device.hubId !== argv.hub) { |
| 65 | return false |
| 66 | } |
| 67 | if (argv.driver && device.driverId !== argv.driver) { |
| 68 | return false |
| 69 | } |
| 70 | return true |
| 71 | } |
| 72 | |
| 73 | const matchingDevices = (await getDriverDevices(command.client)).filter(matchesUserFilters) |
| 74 | |
| 75 | const list = async (): Promise<DeviceDriverInfo[]> => matchingDevices |
| 76 | |
| 77 | const get = async (id: string): Promise<DeviceDriverInfo> => { |
| 78 | const match = matchingDevices.find(device => device.deviceId === id) |
| 79 | if (match) { |
| 80 | return match |
| 81 | } |
| 82 | throw Error(`Could not find device with id ${id}`) |
| 83 | } |
| 84 | |
| 85 | await outputItemOrList(command, config, argv.idOrIndex, list, get) |
| 86 | } |
| 87 | |
| 88 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 89 | export default cmd |
nothing calls this directly
no test coverage detected