forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmv.command.ts
More file actions
57 lines (53 loc) · 2.36 KB
/
Copy pathmv.command.ts
File metadata and controls
57 lines (53 loc) · 2.36 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 { Effect } from "effect";
import { Argument, Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { CliArgs } from "../../../../shared/cli/cli-args.service.ts";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyRequireExperimental } from "../../../shared/legacy-experimental-gate.ts";
import { legacyStorageGatewayRuntimeLayer } from "../../../shared/legacy-storage-runtime.layer.ts";
import {
LegacyStorageLinkedFlagDef,
LegacyStorageLocalFlagDef,
legacyAssertStorageTargetsExclusive,
} from "../storage.flags.ts";
import { legacyStorageMv } from "./mv.handler.ts";
const config = {
src: Argument.string("src").pipe(Argument.withDescription("Source path to move from.")),
dst: Argument.string("dst").pipe(Argument.withDescription("Destination path to move to.")),
recursive: Flag.boolean("recursive").pipe(
Flag.withAlias("r"),
Flag.withDescription("Recursively move a directory."),
),
linked: LegacyStorageLinkedFlagDef,
local: LegacyStorageLocalFlagDef,
} as const;
export type LegacyStorageMvFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacyStorageMvCommand = Command.make("mv", config).pipe(
Command.withDescription("Move objects from src to dst path."),
Command.withShortDescription("Move objects from src to dst path"),
Command.withExamples([
{
command: "supabase storage mv -r ss:///bucket/docs ss:///bucket/www/docs",
description: "Recursively move a directory within storage",
},
]),
Command.withHandler((flags) =>
Effect.gen(function* () {
// Gate before the mutex check below — order matters; see
// legacyRequireExperimental's doc comment for why.
yield* legacyRequireExperimental;
const cliArgs = yield* CliArgs;
yield* legacyAssertStorageTargetsExclusive(cliArgs.args);
const telemetryFlags = {
recursive: flags.recursive,
linked: flags.linked,
local: flags.local,
};
return yield* legacyStorageMv(flags).pipe(
withLegacyCommandInstrumentation({ flags: telemetryFlags }),
);
}).pipe(withJsonErrorHandling),
),
Command.provide(legacyStorageGatewayRuntimeLayer(["storage", "mv"])),
);