( self: Instruction, value: Option.Option<string>, config: CliConfig.CliConfig )
| 392 | } |
| 393 | |
| 394 | const validateInternal = ( |
| 395 | self: Instruction, |
| 396 | value: Option.Option<string>, |
| 397 | config: CliConfig.CliConfig |
| 398 | ): Effect.Effect<any, string, FileSystem.FileSystem> => { |
| 399 | switch (self._tag) { |
| 400 | case "Bool": { |
| 401 | return Option.map(value, (str) => InternalCliConfig.normalizeCase(config, str)).pipe( |
| 402 | Option.match({ |
| 403 | onNone: () => |
| 404 | Effect.orElseFail( |
| 405 | self.defaultValue, |
| 406 | () => `Missing default value for boolean parameter` |
| 407 | ), |
| 408 | onSome: (value) => |
| 409 | isTrueValue(value) |
| 410 | ? Effect.succeed(true) |
| 411 | : isFalseValue(value) |
| 412 | ? Effect.succeed(false) |
| 413 | : Effect.fail(`Unable to recognize '${value}' as a valid boolean`) |
| 414 | }) |
| 415 | ) |
| 416 | } |
| 417 | case "Choice": { |
| 418 | return Effect.orElseFail( |
| 419 | value, |
| 420 | () => `Choice options to not have a default value` |
| 421 | ).pipe( |
| 422 | Effect.flatMap((value) => Arr.findFirst(self.alternatives, ([choice]) => choice === value)), |
| 423 | Effect.mapBoth({ |
| 424 | onFailure: () => { |
| 425 | const choices = pipe( |
| 426 | Arr.map(self.alternatives, ([choice]) => choice), |
| 427 | Arr.join(", ") |
| 428 | ) |
| 429 | return `Expected one of the following cases: ${choices}` |
| 430 | }, |
| 431 | onSuccess: ([, value]) => value |
| 432 | }) |
| 433 | ) |
| 434 | } |
| 435 | case "DateTime": { |
| 436 | return attempt(value, getTypeNameInternal(self), Schema.decodeUnknown(Schema.Date)) |
| 437 | } |
| 438 | case "Float": { |
| 439 | return attempt(value, getTypeNameInternal(self), Schema.decodeUnknown(Schema.NumberFromString)) |
| 440 | } |
| 441 | case "Integer": { |
| 442 | const intFromString = Schema.compose(Schema.NumberFromString, Schema.Int) |
| 443 | return attempt(value, getTypeNameInternal(self), Schema.decodeUnknown(intFromString)) |
| 444 | } |
| 445 | case "Path": { |
| 446 | return Effect.flatMap(FileSystem.FileSystem, (fileSystem) => { |
| 447 | const errorMsg = "Path options do not have a default value" |
| 448 | return Effect.orElseFail(value, () => errorMsg).pipe( |
| 449 | Effect.tap((path) => |
| 450 | Effect.orDie(fileSystem.exists(path)).pipe( |
| 451 | Effect.tap((pathExists) => |
no test coverage detected
searching dependent graphs…