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

Function editItem

src/lib/item-input/array.ts:83–108  ·  view source on GitHub ↗
(itemDef: InputDefinition<T>, list: T[], index: number, context: unknown[])

Source from the content-addressed store, hash-verified

81 }
82
83 const editItem = async (itemDef: InputDefinition<T>, list: T[], index: number, context: unknown[]): Promise<void> => {
84 const currentValue = itemSummary(list[index])
85 const choices: Choice<T | symbol>[] = [editOption(currentValue)]
86 if (list.length > minItems) {
87 choices.push(deleteOption(currentValue))
88 }
89 choices.push(cancelOption)
90
91 const action = await select({
92 message: `What do you want to do with ${currentValue}?`,
93 choices,
94 default: editAction,
95 })
96
97 if (action === editAction) {
98 const response = await itemDef.updateFromUserInput(list[index], context)
99 if (response !== cancelAction) {
100 if (checkForDuplicate(list, response, index)) {
101 list[index] = response
102 }
103 }
104 } else if (action === deleteAction) {
105 list.splice(index, 1)
106 }
107 // Nothing to do for cancelAction
108 }
109
110 // Common code from build and edit
111 const editList = async (list: T[], context: unknown[]): Promise<FinishAction | CancelAction> => {

Callers 1

editListFunction · 0.85

Calls 4

itemSummaryFunction · 0.85
editOptionFunction · 0.85
deleteOptionFunction · 0.85
checkForDuplicateFunction · 0.85

Tested by

no test coverage detected