[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

Support `isAllowEmpty` in multi-select prompt (#42)

authored by

Nate Moore and committed by
GitHub
(Feb 16, 2023, 9:46 PM -0600) dec47289 22e151e2

+11 -1
+6
.changeset/heavy-fishes-change.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + "@clack/core": patch 4 + --- 5 + 6 + Support `required` option for multi-select
+2 -1
packages/core/src/prompts/multi-select.ts
··· 4 4 interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<MultiSelectPrompt<T>> { 5 5 options: T[]; 6 6 initialValue?: T['value'][]; 7 + required?: boolean; 7 8 cursorAt?: T['value'] 8 9 } 9 10 export default class MultiSelectPrompt<T extends { value: any }> extends Prompt { ··· 27 28 constructor(opts: MultiSelectOptions<T>) { 28 29 if (!opts.validate) { 29 30 opts.validate = () => { 30 - if (this.selectedValues.length === 0) return `Please select at least one option\n${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}` 31 + if (opts.required && this.selectedValues.length === 0) return `Please select at least one option\n${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}` 31 32 } 32 33 } 33 34 super(opts, false);
+1
packages/prompts/README.md
··· 104 104 { value: "prettier", label: "Prettier" }, 105 105 { value: "gh-action", label: "GitHub Action" }, 106 106 ], 107 + required: false, 107 108 }); 108 109 ``` 109 110
+2
packages/prompts/src/index.ts
··· 141 141 message: string; 142 142 options: Options; 143 143 initialValue?: Options[number]['value'][]; 144 + required?: boolean; 144 145 cursorAt?: Options[number]["value"] 145 146 } 146 147 ··· 215 216 return new MultiSelectPrompt({ 216 217 options: opts.options, 217 218 initialValue: opts.initialValue, 219 + required: opts.required ?? true, 218 220 cursorAt: opts.cursorAt, 219 221 render() { 220 222 let title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`;