(itemDef: InputDefinition<T>, list: T[], index: number, context: unknown[])
| 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> => { |
no test coverage detected