UNPKG

@cloud-copilot/cli

Version:

A standardized library for CLI building TypeScript CLI applications

35 lines 1.37 kB
/** * Creates an array value argument factory for a specific type */ export function arrayValueArgument(validator, descriptionSuffix = '') { function createArgument(options) { return { description: options.description + descriptionSuffix, validateValues: async (current, values, isCurrentlyDefaulted) => { if (values.length === 0) { return { valid: false, message: 'at least one value is required' }; } const validatedValues = []; for (const rawValue of values) { const result = await validator(rawValue); if (!result.valid) { return result; } validatedValues.push(result.value); } return { valid: true, value: validatedValues }; }, reduceValues: async (current, newValues, isCurrentlyDefaulted) => { if (isCurrentlyDefaulted || !current) { return newValues; } current.push(...newValues); return current; }, defaultValue: options.defaultValue, acceptMultipleValues: () => true }; } return createArgument; } //# sourceMappingURL=arrayValueArgument.js.map