forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.command.ts
More file actions
70 lines (67 loc) · 2.74 KB
/
Copy pathlint.command.ts
File metadata and controls
70 lines (67 loc) · 2.74 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
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyParseSchemaFlags } from "../../../shared/legacy-schema-flags.ts";
import { legacyDbLint } from "./lint.handler.ts";
import { legacyDbLintRuntimeLayer } from "./lint.layers.ts";
const config = {
dbUrl: Flag.string("db-url").pipe(
Flag.withDescription(
"Lints the database specified by the connection string (must be percent-encoded).",
),
Flag.optional,
),
linked: Flag.boolean("linked").pipe(
Flag.withDescription("Lints the linked project for schema errors."),
),
local: Flag.boolean("local").pipe(
Flag.withDescription("Lints the local database for schema errors."),
),
schema: Flag.string("schema").pipe(
Flag.withAlias("s"),
Flag.withDescription("Comma separated list of schema to include."),
Flag.atLeast(0),
Flag.mapTryCatch(
(rawValues) => legacyParseSchemaFlags(rawValues),
(err) => (err instanceof Error ? err.message : String(err)),
),
),
level: Flag.choice("level", ["warning", "error"] as const).pipe(
Flag.withDescription("Error level to emit."),
Flag.optional,
),
failOn: Flag.choice("fail-on", ["none", "warning", "error"] as const).pipe(
Flag.withDescription("Error level to exit with non-zero status."),
Flag.optional,
),
} as const;
export type LegacyDbLintFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacyDbLintCommand = Command.make("lint", config).pipe(
Command.withDescription("Checks local database for typing error."),
Command.withShortDescription("Checks local database for typing error"),
Command.withHandler((flags) =>
legacyDbLint(flags).pipe(
withLegacyCommandInstrumentation({
flags: {
"db-url": flags.dbUrl,
linked: flags.linked,
local: flags.local,
schema: flags.schema,
level: flags.level,
"fail-on": flags.failOn,
},
// level/fail-on are Flag.choice and are auto-detected as safe via
// `config` below (Go's isEnumFlag, cmd/root_analytics.go:110-116).
// --schema stays redacted: it's a []string slice flag in Go, not an EnumFlag.
config,
// Go's changedFlags() uses pflag Visit, which reports the canonical
// `schema` name even for the `-s` shorthand (cmd/db.go:506); map it so
// `db lint -s public` records the schema flag in telemetry.
aliases: { s: "schema" },
}),
withJsonErrorHandling,
),
),
Command.provide(legacyDbLintRuntimeLayer),
);