MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/edge/drivers/package.ts:133–207  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

131 .epilog(buildEpilog({ command, apiDocs: 'uploadDriverPackage' }))
132
133const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
134 const command = await apiOrganizationCommand(argv)
135
136 const uploadAndPostProcess = async (archiveData: Uint8Array): Promise<void> => {
137 const config: OutputItemConfig<EdgeDriver> = {
138 tableFieldDefinitions: ['driverId', 'name', 'packageKey', 'version'],
139 }
140 const driver = await outputItem(command, config, () => command.client.drivers.upload(archiveData))
141 const doAssign = argv.assign || argv.channel || argv.install || argv.hub
142 const doInstall = argv.install || argv.hub
143 if (doAssign) {
144 const driverId = driver.driverId
145 const version = driver.version
146 const channelId = await chooseChannel(
147 command,
148 argv.channel,
149 { useConfigDefault: true, promptMessage: 'Select a channel for the driver.' },
150 )
151 await command.client.channels.assignDriver(channelId, driverId, version)
152 console.log(`Assigned driver ${driverId} (version ${version}) to channel ${channelId}.`)
153
154 if (doInstall) {
155 const hubId = await chooseHub(
156 command,
157 argv.hub,
158 { promptMessage: 'Select a hub to install to.', useConfigDefault: true },
159 )
160 await command.client.hubdevices.installDriver(driverId, hubId, channelId)
161 console.log(`Installed driver ${driverId} (version ${version}) to hub ${hubId}.`)
162 }
163 }
164 }
165
166 if (argv.upload) {
167 try {
168 const data = await readFile(argv.upload)
169 await uploadAndPostProcess(data)
170 } catch (error) {
171 if ((error as { code?: string }).code === 'ENOENT') {
172 return fatalError(`No file named "${argv.upload}" found.`)
173 } else {
174 throw error
175 }
176 }
177 } else {
178 const projectDirectory = await resolveProjectDirName(argv.projectDirectory ?? '.')
179
180 const zip = new JSZip()
181 await processConfigFile(projectDirectory, zip)
182
183 await processFingerprintsFile(projectDirectory, zip)
184 await processSearchParametersFile(projectDirectory, zip)
185 const edgeDriverTestDirs = command.cliConfig.stringArrayConfigValue(
186 'edgeDriverTestDirs',
187 ['test/**', 'tests/**'],
188 )
189 const testFileMatchers = buildTestFileMatchers(edgeDriverTestDirs)
190 if (!await processSrcDir(projectDirectory, zip, testFileMatchers)) {

Callers

nothing calls this directly

Calls 10

apiOrganizationCommandFunction · 0.85
uploadAndPostProcessFunction · 0.85
fatalErrorFunction · 0.85
resolveProjectDirNameFunction · 0.85
processConfigFileFunction · 0.85
processFingerprintsFileFunction · 0.85
buildTestFileMatchersFunction · 0.85
processSrcDirFunction · 0.85
processProfilesFunction · 0.85

Tested by

no test coverage detected