(argv: ArgumentsCamelCase<CommandArgs>)
| 41 | .epilog(buildEpilog({ command })) |
| 42 | |
| 43 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 44 | const command = await apiCommand(argv) |
| 45 | |
| 46 | // A special listItems for `chooseHub` that will only include hubs which are enrolled in channels. |
| 47 | const listItems = async (): Promise<Device[]> => { |
| 48 | const hubs = await listOwnedHubs(command) |
| 49 | const hubsWithChannels = await Promise.all(hubs.map(async hub => |
| 50 | ({ hub, channels: await command.client.hubdevices.enrolledChannels(hub.deviceId) }))) |
| 51 | return hubsWithChannels |
| 52 | .flat() |
| 53 | .filter(({ channels }) => channels.length > 0) |
| 54 | .map(({ hub }) => hub) |
| 55 | } |
| 56 | const hubId = await chooseHub( |
| 57 | command, |
| 58 | argv.hubId, |
| 59 | { useConfigDefault: true, listItems }, |
| 60 | ) |
| 61 | |
| 62 | const channelId = await chooseChannelFn({ includeReadOnly: true })( |
| 63 | command, |
| 64 | argv.channel, |
| 65 | { listItems: () => command.client.hubdevices.enrolledChannels(hubId) }, |
| 66 | ) |
| 67 | |
| 68 | await command.client.channels.unenrollHub(channelId, hubId) |
| 69 | |
| 70 | console.log(`Hub ${hubId} unenrolled from channel ${channelId}.`) |
| 71 | } |
| 72 | |
| 73 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 74 | export default cmd |
nothing calls this directly
no test coverage detected