(argv: ArgumentsCamelCase<CommandArgs>)
| 66 | })) |
| 67 | |
| 68 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 69 | const command = await apiOrganizationCommand(argv) |
| 70 | |
| 71 | const createWithCustomConfig = async (data: DeviceDefinitionRequest): Promise<DeviceDefinition> => { |
| 72 | if (!data.view) { |
| 73 | throw Error('View property not defined') |
| 74 | } |
| 75 | |
| 76 | // create the device config from the view data |
| 77 | const deviceConfig = await command.client.presentation.create(augmentPresentation(data.view)) |
| 78 | |
| 79 | // Set the vid and mnmn from the config |
| 80 | if (!data.metadata) { |
| 81 | data.metadata = {} |
| 82 | } |
| 83 | data.metadata.vid = deviceConfig.presentationId |
| 84 | data.metadata.mnmn = deviceConfig.manufacturerName |
| 85 | delete data.view |
| 86 | |
| 87 | // Create the profile |
| 88 | const profile = await command.client.deviceProfiles.create(cleanupForCreate(data)) |
| 89 | |
| 90 | // Return the composite object |
| 91 | return { ...profile, view: prunePresentation(deviceConfig) } |
| 92 | } |
| 93 | |
| 94 | const createDeviceDefinition = async (_: void, data: DeviceDefinitionRequest): Promise<DeviceDefinition> => { |
| 95 | if (data.view) { |
| 96 | return createWithCustomConfig(data) |
| 97 | } |
| 98 | const profileAndConfig = await createWithDefaultConfig(command.client, data) |
| 99 | return { ...profileAndConfig.deviceProfile, view: prunePresentation(profileAndConfig.deviceConfig) } |
| 100 | } |
| 101 | await inputAndOutputItem( |
| 102 | command, |
| 103 | { buildTableOutput: data => buildTableOutput(command.tableGenerator, data, { includeViewInfo: true }) }, |
| 104 | createDeviceDefinition, |
| 105 | ) |
| 106 | } |
| 107 | |
| 108 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 109 | export default cmd |
nothing calls this directly
no test coverage detected