MCPcopy Create free account
hub / github.com/Effect-TS/effect / validateMinMax

Function validateMinMax

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

Source from the content-addressed store, hash-verified

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