forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.command.ts
More file actions
51 lines (46 loc) · 2.13 KB
/
Copy pathlink.command.ts
File metadata and controls
51 lines (46 loc) · 2.13 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
import { Layer } from "effect";
import { Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { credentialsLayer } from "../../auth/credentials.layer.ts";
import { platformApiLayer } from "../../auth/platform-api.layer.ts";
import { projectLinkRemoteLayer } from "../../config/project-link-remote.layer.ts";
import { projectLinkStateLayer } from "../../config/project-link-state.layer.ts";
import { withJsonErrorHandling } from "../../../shared/output/json-error-handling.ts";
import { commandRuntimeLayer } from "../../../shared/runtime/command-runtime.layer.ts";
import { withCommandInstrumentation } from "../../../shared/telemetry/command-instrumentation.ts";
import { link } from "./link.handler.ts";
const flags = {
projectRef: Flag.string("project-ref").pipe(
Flag.withDescription("Project ref of the Supabase project."),
Flag.optional,
),
} as const;
export type LinkFlags = CliCommand.Command.Config.Infer<typeof flags>;
const linkPlatformApiLayer = platformApiLayer.pipe(Layer.provide(credentialsLayer));
const linkProjectLinkRemoteLayer = projectLinkRemoteLayer.pipe(Layer.provide(linkPlatformApiLayer));
const linkRuntimeLayer = Layer.mergeAll(
linkProjectLinkRemoteLayer,
projectLinkStateLayer,
commandRuntimeLayer(["link"]),
);
export const linkCommand = Command.make("link", flags).pipe(
Command.withDescription(
"Link the current local Supabase project to a hosted Supabase project.\n\n" +
"Stores the linked project ref and cached remote service versions in .supabase/project.json so local startup can match the hosted platform versions.",
),
Command.withShortDescription("Link local project to Supabase"),
Command.withExamples([
{
command: "supabase link",
description: "Pick a project interactively and cache its platform versions",
},
{
command: "supabase link --project-ref abcdefghijklmnopqrst",
description: "Link directly to a specific project ref",
},
]),
Command.withHandler((flags) =>
link(flags).pipe(withCommandInstrumentation(), withJsonErrorHandling),
),
Command.provide(linkRuntimeLayer),
);