forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcp.command.ts
More file actions
88 lines (84 loc) · 3.73 KB
/
Copy pathcp.command.ts
File metadata and controls
88 lines (84 loc) · 3.73 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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 { legacyStorageCp } from "./cp.handler.ts";
// `--linked`/`--local` are scoped globals on the `storage` group. Go's cobra
// help appends a `(default …)` token for every flag with a non-empty default;
// Effect CLI renders no defaults at all, so Go's tokens are reproduced inline in
// the descriptions below to keep `storage cp --help` at parity. `--content-type`
// keeps its empty runtime default (`""` ⇒ auto-detect via sniffing), but Go
// overrides only the *displayed* default to `auto-detect` (`storage.go:106`), so
// the help text — not the resolved value — reads `auto-detect`.
const config = {
src: Argument.string("src").pipe(Argument.withDescription("Source path to copy from.")),
dst: Argument.string("dst").pipe(Argument.withDescription("Destination path to copy to.")),
recursive: Flag.boolean("recursive").pipe(
Flag.withAlias("r"),
Flag.withDescription("Recursively copy a directory."),
),
cacheControl: Flag.string("cache-control").pipe(
Flag.withDescription('Custom Cache-Control header for HTTP upload. (default "max-age=3600")'),
Flag.optional,
),
contentType: Flag.string("content-type").pipe(
Flag.withDescription('Custom Content-Type header for HTTP upload. (default "auto-detect")'),
Flag.optional,
),
jobs: Flag.integer("jobs").pipe(
Flag.withAlias("j"),
Flag.withDescription("Maximum number of parallel jobs. (default 1)"),
Flag.optional,
),
linked: LegacyStorageLinkedFlagDef,
local: LegacyStorageLocalFlagDef,
} as const;
export type LegacyStorageCpFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacyStorageCpCommand = Command.make("cp", config).pipe(
Command.withDescription("Copy objects from src to dst path."),
Command.withShortDescription("Copy objects from src to dst path"),
Command.withExamples([
{
command: "supabase storage cp readme.md ss:///bucket/readme.md",
description: "Upload a local file to storage",
},
{
command: "supabase storage cp -r docs ss:///bucket/docs",
description: "Upload a directory recursively to storage",
},
{
command: "supabase storage cp -r ss:///bucket/docs .",
description: "Download a directory from 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,
cacheControl: flags.cacheControl,
contentType: flags.contentType,
jobs: flags.jobs,
linked: flags.linked,
local: flags.local,
};
return yield* legacyStorageCp(flags).pipe(
withLegacyCommandInstrumentation({ flags: telemetryFlags }),
);
}).pipe(withJsonErrorHandling),
),
Command.provide(legacyStorageGatewayRuntimeLayer(["storage", "cp"])),
);