@flowscripter/flowscripter-io-cli 2.0.11 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +71 -34
  2. package/bun.lock +15 -14
  3. package/functional_tests/features/commands.feature +76 -7
  4. package/functional_tests/features/steps/executable.py +6 -0
  5. package/functional_tests/features/steps/io_commands.py +5 -0
  6. package/package.json +9 -8
  7. package/src/cli.ts +19 -9
  8. package/src/commands/copy.ts +6 -62
  9. package/src/commands/delete.ts +28 -29
  10. package/src/commands/get-properties.ts +30 -34
  11. package/src/commands/hash.ts +102 -68
  12. package/src/commands/list.ts +76 -57
  13. package/src/commands/move.ts +6 -62
  14. package/src/commands/set-properties.ts +92 -37
  15. package/src/commands/transferCommand.ts +121 -0
  16. package/src/util/interruptSignals.ts +70 -0
  17. package/src/util/location/createLocationOption.ts +59 -0
  18. package/src/util/location/describeTarget.ts +6 -0
  19. package/src/util/location/targetKey.ts +9 -0
  20. package/src/util/location/toStructuredLocation.ts +8 -0
  21. package/src/util/payloadKindOption.ts +20 -0
  22. package/src/{pluginsDir.ts → util/pluginsDir.ts} +1 -1
  23. package/src/util/providerRegistry.ts +23 -0
  24. package/src/util/requireOperation.ts +19 -0
  25. package/src/util/zodToComplexOption.ts +93 -0
  26. package/tests/commands/copy.test.ts +80 -0
  27. package/tests/commands/delete.test.ts +44 -0
  28. package/tests/commands/get-properties.test.ts +52 -0
  29. package/tests/commands/hash.test.ts +76 -0
  30. package/tests/commands/list.test.ts +78 -0
  31. package/tests/commands/move.test.ts +45 -0
  32. package/tests/commands/set-properties.test.ts +68 -0
  33. package/tests/commands/transferCommand.test.ts +63 -0
  34. package/tests/fixtures/pluginStore.ts +39 -0
  35. package/tests/{testContext.ts → fixtures/testContext.ts} +17 -1
  36. package/tests/{byteScale_test.ts → util/byteScale.test.ts} +1 -1
  37. package/tests/util/interruptSignals.test.ts +80 -0
  38. package/tests/util/location/createLocationOption.test.ts +73 -0
  39. package/tests/util/location/describeTarget.test.ts +12 -0
  40. package/tests/util/location/targetKey.test.ts +15 -0
  41. package/tests/util/location/toStructuredLocation.test.ts +14 -0
  42. package/tests/util/payloadKindOption.test.ts +19 -0
  43. package/tests/util/providerRegistry.test.ts +39 -0
  44. package/tests/util/requireOperation.test.ts +25 -0
  45. package/tests/util/zodToComplexOption.test.ts +116 -0
  46. package/src/filesystemProvider.ts +0 -40
  47. package/tests/commands_test.ts +0 -186
  48. /package/src/{byteScale.ts → util/byteScale.ts} +0 -0
  49. /package/tests/{cli_test.ts → cli.test.ts} +0 -0
@@ -1,73 +1,106 @@
1
1
  import {
2
+ Icon,
2
3
  PRINTER_SERVICE_ID,
4
+ SHUTDOWN_SERVICE_ID,
3
5
  type Context,
4
6
  type PrinterService,
7
+ type ShutdownService,
5
8
  type SubCommand,
6
9
  type Values,
7
10
  ValueTypeName,
8
11
  } from "@flowscripter/dynamic-cli-framework";
9
- import { ChunkKind, type ChunkRef } from "@flowscripter/pluggable-io-framework-api";
12
+ import type { ProviderRegistry } from "@flowscripter/pluggable-io-framework";
13
+ import { type Item, PayloadKind } from "@flowscripter/pluggable-io-framework-api";
10
14
  import { Sha256Hasher } from "@flowscripter/flowscripter-io-cli-hash-native";
11
- import { getFilesystemProvider } from "../filesystemProvider.ts";
12
- import { createByteScale } from "../byteScale.ts";
15
+ import { createByteScale } from "../util/byteScale.ts";
16
+ import { createLocationOption } from "../util/location/createLocationOption.ts";
17
+ import { toStructuredLocation } from "../util/location/toStructuredLocation.ts";
18
+ import { payloadKindOption, toPayloadKind } from "../util/payloadKindOption.ts";
19
+ import { createInterruptSignals } from "../util/interruptSignals.ts";
13
20
 
14
- const hash: SubCommand = {
15
- name: "hash",
16
- description: "Hash a file by piping its readable stream through a hasher",
17
- positionals: [
18
- {
19
- name: "path",
20
- description: "Path to hash",
21
- type: ValueTypeName.STRING,
22
- },
23
- ],
24
- options: [
25
- {
26
- name: "algorithm",
27
- description: "Hash algorithm",
28
- type: ValueTypeName.STRING,
29
- shortAlias: "a",
30
- isOptional: true,
31
- defaultValue: "sha256",
32
- allowableValues: ["sha1", "sha256", "sha384", "sha512", "md5"],
33
- },
34
- ],
35
- async execute(context: Context, argumentValues: Values): Promise<void> {
36
- const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
37
- const path = argumentValues.path as string;
38
- const algorithm = argumentValues.algorithm as string;
21
+ /**
22
+ * Builds the `hash` command, which consumes a provider's readable stream
23
+ * directly. The first Ctrl-C stops reading and prints the digest of the
24
+ * bytes read so far, marked as stopped; the second cancels.
25
+ */
26
+ export function createHashCommand(registry: ProviderRegistry): SubCommand {
27
+ return {
28
+ name: "hash",
29
+ description: "Hash a file by piping its readable stream through a hasher",
30
+ positionals: [],
31
+ options: [
32
+ createLocationOption(registry, "location", "Location of the file to hash"),
33
+ {
34
+ name: "algorithm",
35
+ description: "Hash algorithm",
36
+ type: ValueTypeName.STRING,
37
+ shortAlias: "a",
38
+ isOptional: true,
39
+ defaultValue: "sha256",
40
+ allowableValues: ["sha1", "sha256", "sha384", "sha512", "md5"],
41
+ },
42
+ payloadKindOption,
43
+ ],
44
+ async execute(context: Context, argumentValues: Values): Promise<void> {
45
+ const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
46
+ const shutdownService = context.getServiceById(SHUTDOWN_SERVICE_ID) as ShutdownService;
47
+ const location = toStructuredLocation(argumentValues.location as Values);
48
+ const algorithm = argumentValues.algorithm as string;
39
49
 
40
- const provider = await getFilesystemProvider("");
41
- try {
42
- const { size } = await provider.getProperties(path);
43
- const byteScale = createByteScale(size ?? 100);
44
- const progressHandle = await printerService.showProgressBar({
45
- message: `Hashing ${path}`,
46
- total: byteScale.total,
47
- format: byteScale.format,
48
- formatRate: byteScale.formatRate,
50
+ const { provider, target } = await registry.createProviderForLocation(location, {
51
+ kind: toPayloadKind(argumentValues["payload-kind"]),
49
52
  });
50
- let bytesProcessed = 0;
51
- const onChunk = (chunkLength: number): void => {
52
- bytesProcessed += chunkLength;
53
- printerService.updateProgressBar(progressHandle, byteScale.scale(bytesProcessed));
54
- };
55
53
  try {
56
- const handle = await provider.getReadableStream(path);
57
- const reader = (handle.stream as ReadableStream<ChunkRef>).getReader();
58
- const digestHex =
59
- algorithm === "sha256"
60
- ? await hashWithNativeSha256(reader, onChunk)
61
- : await hashWithBunCryptoHasher(reader, algorithm, onChunk);
54
+ if (target.kind !== "entry") {
55
+ throw new Error("hash needs a single entry location");
56
+ }
57
+ const path = target.key;
58
+ const { size } = await provider.getProperties(path);
59
+ const byteScale = createByteScale(size ?? 100);
60
+ const progressHandle = await printerService.showProgressBar({
61
+ message: `Hashing ${path}`,
62
+ total: byteScale.total,
63
+ format: byteScale.format,
64
+ formatRate: byteScale.formatRate,
65
+ });
66
+ let bytesProcessed = 0;
67
+ const onChunk = (chunkLength: number): void => {
68
+ bytesProcessed += chunkLength;
69
+ printerService.updateProgressBar(progressHandle, byteScale.scale(bytesProcessed));
70
+ };
71
+ let digestHex: string;
72
+ let stopped: boolean;
73
+ try {
74
+ using signals = createInterruptSignals(shutdownService);
75
+ const handle = await provider.getReadableStream(path);
76
+ const reader = (handle.stream as ReadableStream<Item>).getReader();
77
+ const cancel = () => {
78
+ reader.cancel().catch(() => {});
79
+ };
80
+ signals.stop.addEventListener("abort", cancel);
81
+ signals.signal.addEventListener("abort", cancel);
82
+ digestHex =
83
+ algorithm === "sha256"
84
+ ? await hashWithNativeSha256(reader, onChunk)
85
+ : await hashWithBunCryptoHasher(reader, algorithm, onChunk);
86
+ signals.signal.throwIfAborted();
87
+ stopped = signals.stop.aborted;
88
+ } finally {
89
+ await printerService.hideProgressBar(progressHandle);
90
+ }
91
+ if (stopped) {
92
+ await printerService.print(
93
+ `Hashing stopped after ${bytesProcessed} bytes, digest covers only those bytes\n`,
94
+ Icon.ALERT,
95
+ );
96
+ }
62
97
  await printerService.print(`${digestHex} ${path}\n`);
63
98
  } finally {
64
- await printerService.hideProgressBar(progressHandle);
99
+ await provider[Symbol.asyncDispose]();
65
100
  }
66
- } finally {
67
- await provider[Symbol.asyncDispose]();
68
- }
69
- },
70
- };
101
+ },
102
+ };
103
+ }
71
104
 
72
105
  function toHex(bytes: Uint8Array): string {
73
106
  return Array.from(bytes)
@@ -76,27 +109,28 @@ function toHex(bytes: Uint8Array): string {
76
109
  }
77
110
 
78
111
  async function hashWithNativeSha256(
79
- reader: ReadableStreamDefaultReader<ChunkRef>,
112
+ reader: ReadableStreamDefaultReader<Item>,
80
113
  onChunk: (chunkLength: number) => void,
81
114
  ): Promise<string> {
82
115
  const hasher = new Sha256Hasher();
83
116
  for (;;) {
84
117
  const { done, value } = await reader.read();
85
118
  if (done) break;
86
- if (value.kind === ChunkKind.Js) {
87
- hasher.update(value.data);
88
- onChunk(value.data.byteLength);
119
+ const { payload } = value;
120
+ if (payload.kind === PayloadKind.Js) {
121
+ hasher.update(payload.data);
122
+ onChunk(payload.data.byteLength);
89
123
  } else {
90
- hasher.updatePointer(value.ptr, value.length);
91
- onChunk(value.length);
92
- value.release();
124
+ hasher.updatePointer(payload.ptr, payload.length);
125
+ onChunk(payload.length);
126
+ payload.release();
93
127
  }
94
128
  }
95
129
  return toHex(hasher.final());
96
130
  }
97
131
 
98
132
  async function hashWithBunCryptoHasher(
99
- reader: ReadableStreamDefaultReader<ChunkRef>,
133
+ reader: ReadableStreamDefaultReader<Item>,
100
134
  algorithm: string,
101
135
  onChunk: (chunkLength: number) => void,
102
136
  ): Promise<string> {
@@ -106,14 +140,14 @@ async function hashWithBunCryptoHasher(
106
140
  for (;;) {
107
141
  const { done, value } = await reader.read();
108
142
  if (done) break;
109
- if (value.kind === ChunkKind.Js) {
110
- hasher.update(value.data);
111
- onChunk(value.data.byteLength);
143
+ const { payload } = value;
144
+ if (payload.kind === PayloadKind.Js) {
145
+ hasher.update(payload.data);
146
+ onChunk(payload.data.byteLength);
112
147
  } else {
113
- throw new Error(`hash command only supports js-kind chunks for algorithm "${algorithm}"`);
148
+ payload.release();
149
+ throw new Error(`hash command only supports js-kind payloads for algorithm "${algorithm}"`);
114
150
  }
115
151
  }
116
152
  return hasher.digest("hex");
117
153
  }
118
-
119
- export default hash;
@@ -1,72 +1,91 @@
1
1
  import {
2
+ Icon,
2
3
  PRETTY_PRINTER_SERVICE_ID,
3
4
  PRINTER_SERVICE_ID,
5
+ SHUTDOWN_SERVICE_ID,
4
6
  SYNTAX_HIGHLIGHTER_SERVICE_ID,
5
7
  type Context,
6
8
  type PrettyPrinterService,
7
9
  type PrinterService,
10
+ type ShutdownService,
8
11
  type SubCommand,
9
12
  type SyntaxHighlighterService,
10
13
  type Values,
11
14
  ValueTypeName,
12
15
  } from "@flowscripter/dynamic-cli-framework";
13
- import { getFilesystemProvider } from "../filesystemProvider.ts";
16
+ import { globToRegex, type ProviderRegistry } from "@flowscripter/pluggable-io-framework";
17
+ import { createLocationOption } from "../util/location/createLocationOption.ts";
18
+ import { toStructuredLocation } from "../util/location/toStructuredLocation.ts";
19
+ import { createInterruptSignals, iterateUntilInterrupted } from "../util/interruptSignals.ts";
20
+ import { requireOperation } from "../util/requireOperation.ts";
14
21
 
15
- const list: SubCommand = {
16
- name: "list",
17
- description: "List files/folders, optionally recursive and filtered by regex",
18
- positionals: [
19
- {
20
- name: "path",
21
- description: "Path to list",
22
- type: ValueTypeName.STRING,
23
- },
24
- ],
25
- options: [
26
- {
27
- name: "recursive",
28
- description: "List recursively",
29
- type: ValueTypeName.BOOLEAN,
30
- shortAlias: "r",
31
- isOptional: true,
32
- defaultValue: false,
33
- },
34
- {
35
- name: "regex",
36
- description: "Only list items whose path matches this regex",
37
- type: ValueTypeName.STRING,
38
- shortAlias: "e",
39
- isOptional: true,
40
- },
41
- ],
42
- async execute(context: Context, argumentValues: Values): Promise<void> {
43
- const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
44
- const prettyPrinterService = context.getServiceById(
45
- PRETTY_PRINTER_SERVICE_ID,
46
- ) as PrettyPrinterService;
47
- const syntaxHighlighterService = context.getServiceById(
48
- SYNTAX_HIGHLIGHTER_SERVICE_ID,
49
- ) as SyntaxHighlighterService;
50
- const path = argumentValues.path as string;
51
- const recursive = argumentValues.recursive as boolean | undefined;
52
- const regex = argumentValues.regex as string | undefined;
22
+ /**
23
+ * Builds the `list` command. The first Ctrl-C stops listing gracefully,
24
+ * the second cancels.
25
+ */
26
+ export function createListCommand(registry: ProviderRegistry): SubCommand {
27
+ return {
28
+ name: "list",
29
+ description: "List files/folders, optionally recursive and filtered by regex or pattern",
30
+ positionals: [],
31
+ options: [
32
+ createLocationOption(registry, "location", "Folder or pattern location to list"),
33
+ {
34
+ name: "recursive",
35
+ description: "List recursively",
36
+ type: ValueTypeName.BOOLEAN,
37
+ shortAlias: "r",
38
+ isOptional: true,
39
+ defaultValue: false,
40
+ },
41
+ {
42
+ name: "regex",
43
+ description: "Only list items whose path matches this regex",
44
+ type: ValueTypeName.STRING,
45
+ shortAlias: "e",
46
+ isOptional: true,
47
+ },
48
+ ],
49
+ async execute(context: Context, argumentValues: Values): Promise<void> {
50
+ const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
51
+ const prettyPrinterService = context.getServiceById(
52
+ PRETTY_PRINTER_SERVICE_ID,
53
+ ) as PrettyPrinterService;
54
+ const syntaxHighlighterService = context.getServiceById(
55
+ SYNTAX_HIGHLIGHTER_SERVICE_ID,
56
+ ) as SyntaxHighlighterService;
57
+ const shutdownService = context.getServiceById(SHUTDOWN_SERVICE_ID) as ShutdownService;
58
+ const location = toStructuredLocation(argumentValues.location as Values);
59
+ const recursive = argumentValues.recursive as boolean | undefined;
60
+ const regex = argumentValues.regex as string | undefined;
53
61
 
54
- const provider = await getFilesystemProvider("");
55
- try {
56
- for await (const item of provider.list(path, {
57
- recursive,
58
- regex: regex ? new RegExp(regex) : undefined,
59
- })) {
60
- const pretty = await prettyPrinterService.prettify(
61
- JSON.stringify({ path: item.path, ...item.properties }),
62
- "json",
63
- );
64
- await printerService.print(`${syntaxHighlighterService.highlight(pretty, "json")}\n`);
62
+ const { provider, target } = await registry.createProviderForLocation(location);
63
+ try {
64
+ const list = requireOperation(provider, "list", location.protocol);
65
+ if (target.kind === "entry") {
66
+ throw new Error("list needs a folder or pattern location, not a single entry");
67
+ }
68
+ if (target.kind === "pattern" && regex !== undefined) {
69
+ throw new Error("list accepts either a pattern location or --regex, not both");
70
+ }
71
+ const items =
72
+ target.kind === "pattern"
73
+ ? list(target.containerKey, { recursive, regex: globToRegex(target.pattern) })
74
+ : list(target.key, { recursive, regex: regex ? new RegExp(regex) : undefined });
75
+ using signals = createInterruptSignals(shutdownService);
76
+ for await (const item of iterateUntilInterrupted(items, signals)) {
77
+ const pretty = await prettyPrinterService.prettify(
78
+ JSON.stringify({ path: item.path, ...item.properties }),
79
+ "json",
80
+ );
81
+ await printerService.print(`${syntaxHighlighterService.highlight(pretty, "json")}\n`);
82
+ }
83
+ if (signals.stop.aborted) {
84
+ await printerService.print("Listing stopped before all items were listed\n", Icon.ALERT);
85
+ }
86
+ } finally {
87
+ await provider[Symbol.asyncDispose]();
65
88
  }
66
- } finally {
67
- await provider[Symbol.asyncDispose]();
68
- }
69
- },
70
- };
71
-
72
- export default list;
89
+ },
90
+ };
91
+ }
@@ -1,63 +1,7 @@
1
- import {
2
- Icon,
3
- PRINTER_SERVICE_ID,
4
- type Context,
5
- type PrinterService,
6
- type SubCommand,
7
- type Values,
8
- ValueTypeName,
9
- } from "@flowscripter/dynamic-cli-framework";
10
- import { move as moveProvider } from "@flowscripter/pluggable-io-framework";
11
- import { getFilesystemProvider } from "../filesystemProvider.ts";
12
- import { createByteScale } from "../byteScale.ts";
1
+ import type { SubCommand } from "@flowscripter/dynamic-cli-framework";
2
+ import type { ProviderRegistry } from "@flowscripter/pluggable-io-framework";
3
+ import { createTransferCommand } from "./transferCommand.ts";
13
4
 
14
- const move: SubCommand = {
15
- name: "move",
16
- description: "Move a file, using a direct provider move when possible",
17
- positionals: [
18
- {
19
- name: "source",
20
- description: "Source path",
21
- type: ValueTypeName.STRING,
22
- },
23
- {
24
- name: "destination",
25
- description: "Destination path",
26
- type: ValueTypeName.STRING,
27
- },
28
- ],
29
- options: [],
30
- async execute(context: Context, argumentValues: Values): Promise<void> {
31
- const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
32
- const source = argumentValues.source as string;
33
- const destination = argumentValues.destination as string;
34
-
35
- const provider = await getFilesystemProvider("");
36
- try {
37
- const { size } = await provider.getProperties(source);
38
- const byteScale = createByteScale(size ?? 100);
39
- const handle = await printerService.showProgressBar({
40
- message: `Moving ${source}`,
41
- total: byteScale.total,
42
- format: byteScale.format,
43
- formatRate: byteScale.formatRate,
44
- });
45
- try {
46
- await moveProvider(provider, source, provider, destination, {
47
- telemetry: {
48
- onProgress: (event) => {
49
- printerService.updateProgressBar(handle, byteScale.scale(event.bytesProcessed));
50
- },
51
- },
52
- });
53
- } finally {
54
- await printerService.hideProgressBar(handle);
55
- }
56
- await printerService.print(`Moved ${source} to ${destination}\n`, Icon.SUCCESS);
57
- } finally {
58
- await provider[Symbol.asyncDispose]();
59
- }
60
- },
61
- };
62
-
63
- export default move;
5
+ export function createMoveCommand(registry: ProviderRegistry): SubCommand {
6
+ return createTransferCommand(registry, "move");
7
+ }
@@ -1,4 +1,6 @@
1
1
  import {
2
+ type ComplexOption,
3
+ ComplexValueTypeName,
2
4
  Icon,
3
5
  PRINTER_SERVICE_ID,
4
6
  type Context,
@@ -7,45 +9,98 @@ import {
7
9
  type Values,
8
10
  ValueTypeName,
9
11
  } from "@flowscripter/dynamic-cli-framework";
10
- import { getFilesystemProvider } from "../filesystemProvider.ts";
12
+ import type { ProviderRegistry } from "@flowscripter/pluggable-io-framework";
13
+ import type { EntryPropertyChanges } from "@flowscripter/pluggable-io-framework-api";
14
+ import { createLocationOption } from "../util/location/createLocationOption.ts";
15
+ import { targetKey } from "../util/location/targetKey.ts";
16
+ import { toStructuredLocation } from "../util/location/toStructuredLocation.ts";
17
+ import { requireOperation } from "../util/requireOperation.ts";
18
+ import { zodToComplexOption } from "../util/zodToComplexOption.ts";
11
19
 
12
- const setProperties: SubCommand = {
13
- name: "set-properties",
14
- description: "Set properties of a file/folder",
15
- positionals: [
16
- {
17
- name: "path",
18
- description: "Path to modify",
19
- type: ValueTypeName.STRING,
20
- },
21
- ],
22
- options: [
23
- {
24
- name: "mode",
25
- description: "Unix file mode to apply e.g. 384 for 0o600 (ignored on Windows)",
26
- type: ValueTypeName.NUMBER,
27
- shortAlias: "m",
28
- isOptional: true,
29
- },
30
- ],
31
- async execute(context: Context, argumentValues: Values): Promise<void> {
32
- const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
33
- const path = argumentValues.path as string;
34
- const mode = argumentValues.mode as number | undefined;
20
+ /**
21
+ * The `--properties` argument: one nested group per installed protocol
22
+ * holding that protocol's settable properties, e.g. `--properties.file.mode=384`.
23
+ * Protocols without settable properties have no group.
24
+ */
25
+ function createPropertiesOption(registry: ProviderRegistry): ComplexOption | undefined {
26
+ const groups = registry.getProtocols().flatMap((protocol) => {
27
+ const properties = zodToComplexOption(registry.getFactory(protocol)!.settablePropertySchema);
28
+ return properties.length === 0
29
+ ? []
30
+ : [
31
+ {
32
+ name: protocol,
33
+ description: `Settable properties for the ${protocol} protocol`,
34
+ type: ComplexValueTypeName.COMPLEX as const,
35
+ isOptional: true,
36
+ properties,
37
+ },
38
+ ];
39
+ });
40
+ if (groups.length === 0) {
41
+ return undefined;
42
+ }
43
+ return {
44
+ name: "properties",
45
+ description: "Protocol-specific properties to set",
46
+ type: ComplexValueTypeName.COMPLEX,
47
+ isOptional: true,
48
+ properties: groups,
49
+ };
50
+ }
51
+
52
+ export function createSetPropertiesCommand(registry: ProviderRegistry): SubCommand {
53
+ const propertiesOption = createPropertiesOption(registry);
54
+ return {
55
+ name: "set-properties",
56
+ description: "Set properties of a file/folder",
57
+ positionals: [],
58
+ options: [
59
+ createLocationOption(registry, "location", "Location to modify"),
60
+ {
61
+ name: "last-modified",
62
+ description: "Last modified time to apply, as an ISO 8601 date",
63
+ type: ValueTypeName.STRING,
64
+ isOptional: true,
65
+ validate: (value) =>
66
+ Number.isNaN(Date.parse(value as string)) ? "must be an ISO 8601 date" : undefined,
67
+ },
68
+ {
69
+ name: "content-type",
70
+ description: "Content type to apply",
71
+ type: ValueTypeName.STRING,
72
+ isOptional: true,
73
+ },
74
+ ...(propertiesOption ? [propertiesOption] : []),
75
+ ],
76
+ async execute(context: Context, argumentValues: Values): Promise<void> {
77
+ const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
78
+ const location = toStructuredLocation(argumentValues.location as Values);
79
+ const lastModified = argumentValues["last-modified"] as string | undefined;
80
+ const contentType = argumentValues["content-type"] as string | undefined;
81
+ const properties = (argumentValues.properties as Values | undefined)?.[location.protocol] as
82
+ | Values
83
+ | undefined;
84
+ const changes: EntryPropertyChanges = {
85
+ ...(lastModified !== undefined ? { lastModified: new Date(lastModified) } : {}),
86
+ ...(contentType !== undefined ? { contentType } : {}),
87
+ ...(properties !== undefined ? { properties } : {}),
88
+ };
35
89
 
36
- const provider = await getFilesystemProvider("");
37
- try {
38
- await printerService.showSpinner(`Setting properties for ${path}...`);
90
+ const { provider, target } = await registry.createProviderForLocation(location);
39
91
  try {
40
- await provider.setProperties(path, mode !== undefined ? { mode } : {});
92
+ const setProperties = requireOperation(provider, "setProperties", location.protocol);
93
+ const key = targetKey(target, "set-properties");
94
+ await printerService.showSpinner(`Setting properties for ${key}...`);
95
+ try {
96
+ await setProperties(key, changes);
97
+ } finally {
98
+ await printerService.hideSpinner();
99
+ }
100
+ await printerService.print(`Updated properties for ${key}\n`, Icon.SUCCESS);
41
101
  } finally {
42
- await printerService.hideSpinner();
102
+ await provider[Symbol.asyncDispose]();
43
103
  }
44
- await printerService.print(`Updated properties for ${path}\n`, Icon.SUCCESS);
45
- } finally {
46
- await provider[Symbol.asyncDispose]();
47
- }
48
- },
49
- };
50
-
51
- export default setProperties;
104
+ },
105
+ };
106
+ }