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

Function buildFromUserInput

src/lib/item-input/object.ts:121–145  ·  view source on GitHub ↗
(context: unknown[] = [])

Source from the content-addressed store, hash-verified

119export function objectDef<T extends object>(name: string, inputDefsByProperty: InputDefsByProperty<T>,
120 options?: ObjectDefOptions<T>): InputDefinition<T> {
121 const buildFromUserInput = async (context: unknown[] = []): Promise<T | CancelAction> => {
122 // Since we're just going to run through all the options and ask for their value, we don't
123 // have a menu or any place to put help for the whole object so we'll just display it
124 // before asking the questions.
125 if (options?.helpText) {
126 console.log(`\n${options.helpText}\n`)
127 }
128 const retVal = {} as Partial<T>
129 for (const propertyName in inputDefsByProperty) {
130 const propertyInputDefinition = inputDefsByProperty[propertyName]
131 // Allow `undefined` definitions, but do nothing with them. This allows callers of
132 // `objectDef` to have a field skipped by setting it to `undefined` as well as by leaving
133 // it out.
134 if (!propertyInputDefinition) {
135 continue
136 }
137 const value = await propertyInputDefinition.buildFromUserInput([{ ...retVal }, ...context])
138 if (value !== cancelAction) {
139 retVal[propertyName] = value
140 } else {
141 return cancelAction
142 }
143 }
144 return retVal as T
145 }
146
147 const summarizeForEdit = options?.summarizeForEdit ?? defaultSummarizeForEditFn(name)
148

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected