MCPcopy
hub / github.com/serverless/serverless / choose

Method choose

packages/util/src/logger/index.js:843–886  ·  view source on GitHub ↗

* Renders a select prompt to the console. * @param param.message string * @param param.choices any[] * @returns

({ message, choices, onCancel })

Source from the content-addressed store, hash-verified

841 * @returns
842 */
843 async choose({ message, choices, onCancel }) {
844 // Stop the spinner to not collide with prompt
845 renderer.spinner.stop()
846
847 const enquirer = new Enquirer()
848
849 // Mapping names to values for result processing
850 const nameToValueMap = choices.reduce((map, choice) => {
851 map[choice.name] = choice.value
852 return map
853 }, {})
854
855 const answer = await enquirer.prompt({
856 type: 'select',
857 name: 'select',
858 choices: choices.map((choice) => choice.name),
859 message: renderer.colors.default(message),
860 styles: {
861 danger: renderer.colors.red, // This sets the color for the error message
862 primary: renderer.colors.red, // This sets the primary color to red
863 submitted: renderer.colors.red, // Assuming 'submitted' is the correct property for the final input
864 },
865 result(name) {
866 // Return the value corresponding to the selected name
867 return nameToValueMap[name]
868 },
869 onCancel: () => {
870 if (onCancel) {
871 return onCancel()
872 }
873 const err = new Error('Canceled')
874 err.stack = undefined
875 throw err
876 },
877 })
878
879 // Save the last selected value
880 renderer.state.lastToken = answer.select
881
882 // Restart the spinner if it was stopped
883 renderer.spinner.start()
884
885 return answer.select
886 }
887
888 async checkbox({ message, choices, initial }) {
889 // Stop the spinner to not collide with prompt

Callers 8

routeNewFunction · 0.80
ensureAppInConfigFileFunction · 0.80
createAwsCredentialsFunction · 0.80
commandSupportFunction · 0.80
getAuthenticatedDataMethod · 0.80
unAuthenticateMethod · 0.80

Calls 2

stopMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected