|
1 | 1 | import { describe, expect, it } from "@effect/vitest" |
2 | | -import { Effect, Either } from "effect" |
| 2 | +import { Effect } from "effect" |
3 | 3 |
|
4 | | -import { type Command, defaultTemplateConfig } from "@effect-template/lib/core/domain" |
| 4 | +import { defaultTemplateConfig } from "@effect-template/lib/core/domain" |
5 | 5 | import { expandContainerHome } from "@effect-template/lib/usecases/scrap-path" |
6 | | -import { parseArgs } from "../../src/docker-git/cli/parser.js" |
7 | | - |
8 | | -type CreateCommand = Extract<Command, { _tag: "Create" }> |
9 | | - |
10 | | -const expectParseErrorTag = ( |
11 | | - args: ReadonlyArray<string>, |
12 | | - expectedTag: string |
13 | | -) => |
14 | | - Effect.sync(() => { |
15 | | - const parsed = parseArgs(args) |
16 | | - Either.match(parsed, { |
17 | | - onLeft: (error) => { |
18 | | - expect(error._tag).toBe(expectedTag) |
19 | | - }, |
20 | | - onRight: () => { |
21 | | - throw new Error("expected parse error") |
22 | | - } |
23 | | - }) |
24 | | - }) |
25 | | - |
26 | | -const parseOrThrow = (args: ReadonlyArray<string>): Command => { |
27 | | - const parsed = parseArgs(args) |
28 | | - return Either.match(parsed, { |
29 | | - onLeft: (error) => { |
30 | | - throw new Error(`unexpected error ${error._tag}`) |
31 | | - }, |
32 | | - onRight: (command) => command |
33 | | - }) |
34 | | -} |
35 | | - |
36 | | -type ProjectDirRunUpCommand = Extract<Command, { readonly projectDir: string; readonly runUp: boolean }> |
37 | | - |
38 | | -const expectProjectDirRunUpCommand = ( |
39 | | - args: ReadonlyArray<string>, |
40 | | - expectedTag: ProjectDirRunUpCommand["_tag"], |
41 | | - expectedProjectDir: string, |
42 | | - expectedRunUp: boolean |
43 | | -) => |
44 | | - Effect.sync(() => { |
45 | | - const command = parseOrThrow(args) |
46 | | - if (command._tag !== expectedTag) { |
47 | | - throw new Error(`expected ${expectedTag} command`) |
48 | | - } |
49 | | - if (!("projectDir" in command) || !("runUp" in command)) { |
50 | | - throw new Error("expected command with projectDir and runUp") |
51 | | - } |
52 | | - expect(command.projectDir).toBe(expectedProjectDir) |
53 | | - expect(command.runUp).toBe(expectedRunUp) |
54 | | - }) |
55 | | - |
56 | | -const expectAttachProjectDirCommand = ( |
57 | | - args: ReadonlyArray<string>, |
58 | | - expectedProjectDir: string |
59 | | -) => |
60 | | - Effect.sync(() => { |
61 | | - const command = parseOrThrow(args) |
62 | | - if (command._tag !== "Attach") { |
63 | | - throw new Error("expected Attach command") |
64 | | - } |
65 | | - expect(command.projectDir).toBe(expectedProjectDir) |
66 | | - }) |
67 | | - |
68 | | -const expectCreateCommand = ( |
69 | | - args: ReadonlyArray<string>, |
70 | | - onRight: (command: CreateCommand) => void |
71 | | -) => |
72 | | - Effect.sync(() => { |
73 | | - const command = parseOrThrow(args) |
74 | | - if (command._tag !== "Create") { |
75 | | - throw new Error("expected Create command") |
76 | | - } |
77 | | - onRight(command) |
78 | | - }) |
| 6 | +import { |
| 7 | + type CreateCommand, |
| 8 | + expectAttachProjectDirCommand, |
| 9 | + expectCreateCommand, |
| 10 | + expectParseErrorTag, |
| 11 | + expectProjectDirRunUpCommand, |
| 12 | + parseOrThrow |
| 13 | +} from "./parser-helpers.js" |
79 | 14 |
|
80 | 15 | const expectCreateDefaults = (command: CreateCommand) => { |
81 | 16 | expect(command.config.repoUrl).toBe("https://github.com/org/repo.git") |
|
0 commit comments