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

Function handler

src/commands/apps/oauth/generate.ts:48–83  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

46 .epilog(buildEpilog({ command, apiDocs: [docNames] }))
47
48const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
49 const command = await apiCommand(argv)
50
51 const appId = await chooseApp(command, argv.id)
52
53 const tableFieldDefinitions: TableFieldDefinition<GenerateAppOAuthResponse>[] = [
54 { path: 'oauthClientDetails.clientName' },
55 { path: 'oauthClientDetails.scope' },
56 { path: 'oauthClientDetails.redirectUris' },
57 'oauthClientId',
58 'oauthClientSecret',
59 ]
60 const config: InputAndOutputItemConfig<GenerateAppOAuthResponse> = {
61 tableFieldDefinitions,
62 }
63 const getInputFromUser = async (): Promise<GenerateAppOAuthRequest> => {
64 const originalOauth = await command.client.apps.getOauth(appId)
65 const startingRequest: GenerateAppOAuthRequest = {
66 clientName: originalOauth.clientName,
67 scope: originalOauth.scope ?? [],
68 }
69 const inputDef = objectDef('Generate Request', {
70 clientName: stringDef('Client Name'),
71 scope: oauthAppScopeDef,
72 }, { helpText: itemInputHelpText(docNames) })
73
74 return updateFromUserInput(command, inputDef, startingRequest, { dryRun: !!argv.dryRun })
75 }
76
77 await inputAndOutputItem(
78 command,
79 config,
80 (_, data: GenerateAppOAuthRequest) => command.client.apps.regenerateOauth(appId, data),
81 inputProcessor(() => true, getInputFromUser),
82 )
83}
84
85const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
86export default cmd

Callers

nothing calls this directly

Calls 3

apiCommandFunction · 0.85
inputAndOutputItemFunction · 0.85
inputProcessorFunction · 0.85

Tested by

no test coverage detected