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

Function editValue

src/lib/item-input/select.ts:54–81  ·  view source on GitHub ↗
(defaultSelection: T | undefined)

Source from the content-addressed store, hash-verified

52 const namesByValue = new Map(choices.map(choice => [valueOfChoice(choice), nameOfChoice(choice)]))
53
54 const editValue = async (defaultSelection: T | undefined): Promise<T | CancelAction> => {
55 const inquirerChoices: (Choice<T | CancelAction | HelpAction>)[] = choices.map(choice => ({
56 name: nameOfChoice(choice),
57 value: valueOfChoice(choice),
58 }))
59
60 inquirerChoices.push(new Separator())
61 if (options?.helpText) {
62 inquirerChoices.push(helpOption)
63 }
64 inquirerChoices.push(cancelOption)
65
66 // eslint-disable-next-line no-constant-condition
67 while (true) {
68 const selection = await select({
69 message: `Select ${name}.`,
70 choices: inquirerChoices,
71 default: defaultSelection ?? 0,
72 pageSize: inquirerPageSize,
73 })
74
75 if (selection === helpAction) {
76 console.log(`\n${options?.helpText}\n`)
77 } else {
78 return selection
79 }
80 }
81 }
82
83 const buildFromUserInput = (): Promise<T | CancelAction> => editValue(options?.default)
84

Callers 2

buildFromUserInputFunction · 0.85
updateFromUserInputFunction · 0.85

Calls 2

nameOfChoiceFunction · 0.85
valueOfChoiceFunction · 0.85

Tested by

no test coverage detected