@cloud-copilot/cli
Version:
A standardized library for CLI building TypeScript CLI applications
32 lines • 1.32 kB
JavaScript
export function enumArgument(options) {
return {
description: options.description +
`. One value required, valid values are: ${options.validValues.join(', ')}`,
validateValues: (currentValue, values) => {
if (values.length == 0) {
return { valid: false, message: 'a value is required' };
}
if (currentValue != options.defaultValue) {
return { valid: false, message: 'expects a single value but was set multiple times' };
}
if (values.length > 1) {
return {
valid: false,
message: 'expects a single value but received ' + values.join(', ')
};
}
const value = values[0];
const match = options.validValues.find((v) => v.toLowerCase() === value.toLowerCase());
if (!match) {
return {
valid: false,
message: `${value} is not one of the allowed values: ${options.validValues.join(', ')}`
};
}
return { valid: true, value: match };
},
reduceValues: (current, newValue) => newValue,
defaultValue: options.defaultValue
};
}
//# sourceMappingURL=enumArgument.js.map