MCPcopy Index your code
hub / github.com/Effect-TS/effect / validateMinMax

Function validateMinMax

packages/cli/src/internal/options.ts:1318–1335  ·  view source on GitHub ↗
(values: ReadonlyArray<string>)

Source from the content-addressed store, hash-verified

1316 const max = Option.getOrElse(self.max, () => Number.MAX_SAFE_INTEGER)
1317 const matchedArgument = Arr.filterMap(getNames(self), (name) => HashMap.get(args, name))
1318 const validateMinMax = (values: ReadonlyArray<string>) => {
1319 if (values.length < min) {
1320 const name = self.argumentOption.fullName
1321 const error = `Expected at least ${min} value(s) for option: '${name}'`
1322 return Effect.fail(InternalValidationError.invalidValue(InternalHelpDoc.p(error)))
1323 }
1324 if (values.length > max) {
1325 const name = self.argumentOption.fullName
1326 const error = `Expected at most ${max} value(s) for option: '${name}'`
1327 return Effect.fail(InternalValidationError.invalidValue(InternalHelpDoc.p(error)))
1328 }
1329 const primitive = self.argumentOption.primitiveType
1330 const validatePrimitive = (value: string) =>
1331 InternalPrimitive.validate(primitive, Option.some(value), config).pipe(
1332 Effect.mapError((e) => InternalValidationError.invalidValue(InternalHelpDoc.p(e)))
1333 )
1334 return Effect.forEach(values, (value) => validatePrimitive(value))
1335 }
1336 // If we did not receive any variadic arguments then perform the bounds
1337 // checks with an empty array
1338 if (Arr.every(matchedArgument, Arr.isEmptyReadonlyArray)) {

Callers 1

parseInternalFunction · 0.85

Calls 2

validatePrimitiveFunction · 0.85
failMethod · 0.65

Tested by

no test coverage detected