forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.command.ts
More file actions
57 lines (50 loc) · 2.48 KB
/
Copy pathnew.command.ts
File metadata and controls
57 lines (50 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Layer } from "effect";
import { Argument, Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { legacyCliConfigLayer } from "../../../config/legacy-cli-config.layer.ts";
import { legacyDebugLoggerLayer } from "../../../shared/legacy-debug-logger.layer.ts";
import { legacyTelemetryStateLayer } from "../../../telemetry/legacy-telemetry-state.layer.ts";
import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.layer.ts";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyTestNew } from "./new.handler.ts";
const TEMPLATE_VALUES = ["pgtap"] as const;
const config = {
name: Argument.string("name").pipe(Argument.withDescription("Name of the test file to create.")),
template: Flag.choice("template", TEMPLATE_VALUES).pipe(
Flag.withAlias("t"),
Flag.withDescription("Template framework to generate."),
Flag.optional,
),
} as const;
export type LegacyTestNewFlags = CliCommand.Command.Config.Infer<typeof config>;
// `test new` writes a local file and makes no Management API calls, so it avoids
// `legacyManagementApiRuntimeLayer` (which eagerly resolves an access token).
// `legacyCliConfigLayer` provides the resolved `workdir`; `Layer.provide` does not
// share to siblings inside a merge, so it is exposed at the top level too.
const cliConfig = legacyCliConfigLayer.pipe(Layer.provide(legacyDebugLoggerLayer));
const legacyTestNewRuntimeLayer = Layer.mergeAll(
cliConfig,
legacyTelemetryStateLayer,
commandRuntimeLayer(["test", "new"]),
);
export const legacyTestNewCommand = Command.make("new", config).pipe(
Command.withDescription("Create a new test file."),
Command.withShortDescription("Create a new test file"),
Command.withHandler((flags) =>
legacyTestNew(flags).pipe(
withLegacyCommandInstrumentation({
flags,
config,
// `--template` registers `-t` (Flag.withAlias above); without this,
// `-t pgtap` never resolves to the canonical `template` name in
// extractChangedFlagNames, so it wouldn't appear in telemetry at all
// (Go's pflag.Visit reports the canonical name regardless of shorthand —
// cmd/root_analytics.go:53-76).
aliases: { t: "template" },
}),
withJsonErrorHandling,
),
),
Command.provide(legacyTestNewRuntimeLayer),
);