@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.
- package/README.md +71 -34
- package/bun.lock +15 -14
- package/functional_tests/features/commands.feature +76 -7
- package/functional_tests/features/steps/executable.py +6 -0
- package/functional_tests/features/steps/io_commands.py +5 -0
- package/package.json +9 -8
- package/src/cli.ts +19 -9
- package/src/commands/copy.ts +6 -62
- package/src/commands/delete.ts +28 -29
- package/src/commands/get-properties.ts +30 -34
- package/src/commands/hash.ts +102 -68
- package/src/commands/list.ts +76 -57
- package/src/commands/move.ts +6 -62
- package/src/commands/set-properties.ts +92 -37
- package/src/commands/transferCommand.ts +121 -0
- package/src/util/interruptSignals.ts +70 -0
- package/src/util/location/createLocationOption.ts +59 -0
- package/src/util/location/describeTarget.ts +6 -0
- package/src/util/location/targetKey.ts +9 -0
- package/src/util/location/toStructuredLocation.ts +8 -0
- package/src/util/payloadKindOption.ts +20 -0
- package/src/{pluginsDir.ts → util/pluginsDir.ts} +1 -1
- package/src/util/providerRegistry.ts +23 -0
- package/src/util/requireOperation.ts +19 -0
- package/src/util/zodToComplexOption.ts +93 -0
- package/tests/commands/copy.test.ts +80 -0
- package/tests/commands/delete.test.ts +44 -0
- package/tests/commands/get-properties.test.ts +52 -0
- package/tests/commands/hash.test.ts +76 -0
- package/tests/commands/list.test.ts +78 -0
- package/tests/commands/move.test.ts +45 -0
- package/tests/commands/set-properties.test.ts +68 -0
- package/tests/commands/transferCommand.test.ts +63 -0
- package/tests/fixtures/pluginStore.ts +39 -0
- package/tests/{testContext.ts → fixtures/testContext.ts} +17 -1
- package/tests/{byteScale_test.ts → util/byteScale.test.ts} +1 -1
- package/tests/util/interruptSignals.test.ts +80 -0
- package/tests/util/location/createLocationOption.test.ts +73 -0
- package/tests/util/location/describeTarget.test.ts +12 -0
- package/tests/util/location/targetKey.test.ts +15 -0
- package/tests/util/location/toStructuredLocation.test.ts +14 -0
- package/tests/util/payloadKindOption.test.ts +19 -0
- package/tests/util/providerRegistry.test.ts +39 -0
- package/tests/util/requireOperation.test.ts +25 -0
- package/tests/util/zodToComplexOption.test.ts +116 -0
- package/src/filesystemProvider.ts +0 -40
- package/tests/commands_test.ts +0 -186
- /package/src/{byteScale.ts → util/byteScale.ts} +0 -0
- /package/tests/{cli_test.ts → cli.test.ts} +0 -0
package/README.md
CHANGED
|
@@ -37,53 +37,90 @@ Via [Winget](https://github.com/microsoft/winget-cli):
|
|
|
37
37
|
You can download and extract the binary zip files from the
|
|
38
38
|
[releases](https://github.com/flowscripter/flowscripter-io-cli/releases) page.
|
|
39
39
|
|
|
40
|
+
## Locations
|
|
41
|
+
|
|
42
|
+
Every command addresses data through a location argument: `--source` and
|
|
43
|
+
`--dest` for `copy`/`move`, and `--location` for the other commands. A
|
|
44
|
+
location has a `protocol` and one group of fields per installed protocol:
|
|
45
|
+
|
|
46
|
+
- `--location.protocol=file` selects the protocol. The allowed values are
|
|
47
|
+
the protocols of the installed provider plugins.
|
|
48
|
+
- `--location.file.path=/data` and the other fields of the selected protocol
|
|
49
|
+
are taken from that protocol's provider plugin, and are validated against
|
|
50
|
+
it.
|
|
51
|
+
- For `file` (and other protocols with folders), a location with a
|
|
52
|
+
`filename` addresses one file, one with a `pattern` (a glob such as
|
|
53
|
+
`*.txt`) addresses the matching files in `path`, and one with neither
|
|
54
|
+
addresses the whole `path` folder.
|
|
55
|
+
|
|
56
|
+
`flowscripter-io-cli <command> --help` lists the fields of every installed
|
|
57
|
+
protocol.
|
|
58
|
+
|
|
40
59
|
## Commands
|
|
41
60
|
|
|
42
|
-
- `list
|
|
43
|
-
|
|
44
|
-
- `
|
|
45
|
-
- `
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
- `list --location [--recursive] [--regex]` - list a folder, or the files
|
|
62
|
+
matching a pattern location, one JSON line per item
|
|
63
|
+
- `get-properties --location` - print a file or folder's properties as JSON
|
|
64
|
+
- `set-properties --location [--last-modified] [--content-type]
|
|
65
|
+
[--properties.<protocol>.<name>]` - set properties: last modified time and
|
|
66
|
+
content type apply to every protocol, and `--properties` holds one group
|
|
67
|
+
per protocol for its own settable properties (e.g.
|
|
68
|
+
`--properties.file.mode=384`)
|
|
69
|
+
- `delete --location` - delete a file or folder
|
|
70
|
+
- `copy --source --dest [--payload-kind]` - copy a file, a folder, or the
|
|
71
|
+
files matching a pattern, using a direct provider copy when possible, with
|
|
72
|
+
a progress bar for a single file. Prints the negotiated transfer path,
|
|
73
|
+
e.g. `path: file/js -> file/js, direct`
|
|
74
|
+
- `move --source --dest [--payload-kind]` - move, with the same behaviour as
|
|
75
|
+
`copy`
|
|
76
|
+
- `hash --location [--algorithm] [--payload-kind]` - hash a file by reading
|
|
77
|
+
its stream directly, outside the framework's transfer path. `--algorithm`
|
|
78
|
+
is one of `sha1`, `sha256` (the default, using a native hasher), `sha384`,
|
|
79
|
+
`sha512` or `md5`
|
|
80
|
+
|
|
81
|
+
Common behaviour:
|
|
82
|
+
|
|
83
|
+
- `--payload-kind` is `auto` (the default, letting the registry choose),
|
|
84
|
+
`js` or `native`. An unavailable kind fails with the kinds that are
|
|
85
|
+
installed.
|
|
86
|
+
- During `list`, `copy`, `move` or `hash`, the first Ctrl-C stops gracefully and
|
|
87
|
+
reports the result as stopped, and a second Ctrl-C cancels.
|
|
88
|
+
- Operations a protocol does not support (e.g. `list` over `https`) fail with
|
|
89
|
+
a "not supported by protocol" error.
|
|
90
|
+
- Any required argument omitted on the command line is prompted for
|
|
91
|
+
interactively, via
|
|
48
92
|
[dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)'s
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
`--algorithm` is restricted to a curated set (`sha1`, `sha256`, `sha384`,
|
|
56
|
-
`sha512`, `md5`)
|
|
57
|
-
|
|
58
|
-
Any argument omitted on the command line (e.g. running `copy` with no
|
|
59
|
-
`source`/`destination`) is interactively prompted for instead of failing,
|
|
60
|
-
via [dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)'s
|
|
61
|
-
`ArgumentPrompterService`. Confirmation messages (`copy`, `move`, `delete`,
|
|
62
|
-
`set-properties`) are prefixed with a success icon.
|
|
63
|
-
|
|
64
|
-
All commands operate against a filesystem source/sink provider - rooted at
|
|
65
|
-
`/`, so any absolute or cwd-relative path works, the same as any normal file
|
|
66
|
-
tool. **This package has no dependency on any provider plugin** - one must
|
|
67
|
-
be installed first via the CLI's own plugin management (provided by
|
|
93
|
+
`ArgumentPrompterService`.
|
|
94
|
+
|
|
95
|
+
## Provider Plugins
|
|
96
|
+
|
|
97
|
+
This package has no dependency on any provider plugin. Install one or more
|
|
98
|
+
through the CLI's own plugin management (provided by
|
|
68
99
|
[dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)'s
|
|
69
|
-
`plugin` commands)
|
|
100
|
+
`plugin` commands). They are discovered at startup through
|
|
70
101
|
[dynamic-plugin-framework](https://github.com/flowscripter/dynamic-plugin-framework)'s
|
|
71
|
-
`NpmPluginRepository
|
|
102
|
+
`NpmPluginRepository`, and several protocols, or several implementations of
|
|
103
|
+
one protocol, can be installed side by side:
|
|
72
104
|
|
|
73
105
|
```
|
|
74
|
-
|
|
106
|
+
flowscripter-io-cli plugin:add @flowscripter/io-plugin-filesystem
|
|
75
107
|
```
|
|
76
108
|
|
|
77
109
|
## Usage
|
|
78
110
|
|
|
79
|
-
Once installed (see [Installation](#installation))
|
|
80
|
-
below with `flowscripter-io-cli`:
|
|
111
|
+
Once installed (see [Installation](#installation)):
|
|
81
112
|
|
|
82
113
|
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
114
|
+
flowscripter-io-cli plugin:add @flowscripter/io-plugin-filesystem
|
|
115
|
+
flowscripter-io-cli list --location.protocol=file --location.file.path=.
|
|
116
|
+
flowscripter-io-cli copy \
|
|
117
|
+
--source.protocol=file --source.file.path=. --source.file.filename=a.txt \
|
|
118
|
+
--dest.protocol=file --dest.file.path=. --dest.file.filename=b.txt
|
|
119
|
+
flowscripter-io-cli copy \
|
|
120
|
+
--source.protocol=file --source.file.path=. --source.file.pattern='*.txt' \
|
|
121
|
+
--dest.protocol=file --dest.file.path=backup
|
|
122
|
+
flowscripter-io-cli hash --location.protocol=file --location.file.path=. \
|
|
123
|
+
--location.file.filename=a.txt --algorithm sha256
|
|
87
124
|
```
|
|
88
125
|
|
|
89
126
|
## Development
|
package/bun.lock
CHANGED
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/flowscripter-io-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
9
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
10
|
-
"@flowscripter/dynamic-plugin-framework": "^2.2.
|
|
11
|
-
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.
|
|
12
|
-
"@flowscripter/pluggable-io-framework": "^1.
|
|
13
|
-
"@flowscripter/pluggable-io-framework-api": "^1.1
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "^9.0.0",
|
|
9
|
+
"@flowscripter/dynamic-cli-framework-api": "^5.0.0",
|
|
10
|
+
"@flowscripter/dynamic-plugin-framework": "^2.2.19",
|
|
11
|
+
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.13",
|
|
12
|
+
"@flowscripter/pluggable-io-framework": "^2.1.0",
|
|
13
|
+
"@flowscripter/pluggable-io-framework-api": "^3.1.1",
|
|
14
|
+
"zod": "^4.6.5",
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
|
-
"@flowscripter/io-plugin-filesystem": "^
|
|
17
|
+
"@flowscripter/io-plugin-filesystem": "^2.0.2",
|
|
17
18
|
"@types/bun": "^1.4.2",
|
|
18
19
|
"@types/node": "^26.6.3",
|
|
19
20
|
"oxfmt": "0.71.0",
|
|
@@ -25,19 +26,19 @@
|
|
|
25
26
|
},
|
|
26
27
|
},
|
|
27
28
|
"packages": {
|
|
28
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@
|
|
29
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@9.0.0", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^5.0.0", "@flowscripter/dynamic-plugin-framework": "^2.2.16", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.12.0", "highlight.js": "^11.12.0", "prettier": "^3.9.9", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-CUPz8Iusp1tTTpVAHUdDYNk/tQuQwsZEt7wmomxmjCEI4s/4ROde0qIvvqsqfx5jHF84vvjoxbQ5Uhdm79evwA=="],
|
|
29
30
|
|
|
30
|
-
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@
|
|
31
|
+
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@5.0.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-mF2V1Np+MKSQqeXGJO8WWT2dNiVlAKg1gFrf+lPriWBXLZFyv9JU44gDYtCMfenQuoaHMb3IgOwIfVeBclvYhQ=="],
|
|
31
32
|
|
|
32
|
-
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.
|
|
33
|
+
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.19", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-sAJppm6IyDdNJjOH5Bh/odrsb5vXNwgBGdU1NITjR3LqaJRFLTfuSepvX00NEgcUt3DMRmxJYiUyGrEJimLJgQ=="],
|
|
33
34
|
|
|
34
|
-
"@flowscripter/flowscripter-io-cli-hash-native": ["@flowscripter/flowscripter-io-cli-hash-native@1.0.
|
|
35
|
+
"@flowscripter/flowscripter-io-cli-hash-native": ["@flowscripter/flowscripter-io-cli-hash-native@1.0.13", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-I5jCqiHvDMenNajwT075dVQxgYxbPuDAqtJcrQf/el+U2Wh+Xj7E0/fOoMeDq0kOZY+zZmr/7KeYBow/FzLxpA=="],
|
|
35
36
|
|
|
36
|
-
"@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@
|
|
37
|
+
"@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@2.0.2", "", { "dependencies": { "@flowscripter/pluggable-io-framework-api": "^3.1.1", "zod": "^4.6.5" }, "peerDependencies": { "@flowscripter/dynamic-plugin-framework": "*", "typescript": "^7.0.2" } }, "sha512-Tze5MN0KqGWOrqP+3pxa+wrCkNxW0fdPOLHcPyNphwmepP8Q1VOL+/8hil//qeIiEmIEdWr4BLWaJM9+NSH+fg=="],
|
|
37
38
|
|
|
38
|
-
"@flowscripter/pluggable-io-framework": ["@flowscripter/pluggable-io-framework@1.
|
|
39
|
+
"@flowscripter/pluggable-io-framework": ["@flowscripter/pluggable-io-framework@2.1.0", "", { "dependencies": { "@flowscripter/dynamic-plugin-framework": "^2.2.18", "@flowscripter/pluggable-io-framework-api": "^3.1.1" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-x3KnImZpuY5J24+iGOOJci8Rk12l7nBCq/jKJWINJuZLKqFtPYXRtVff5V7gOFlnBE6fiKNp0UL26clcsYhk6Q=="],
|
|
39
40
|
|
|
40
|
-
"@flowscripter/pluggable-io-framework-api": ["@flowscripter/pluggable-io-framework-api@1.1
|
|
41
|
+
"@flowscripter/pluggable-io-framework-api": ["@flowscripter/pluggable-io-framework-api@3.1.1", "", { "dependencies": { "zod": "^4.6.5", "zod-to-json-schema": "^3.25.2" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-AnXneT+Qrr+/vkgoghOn857SOmjy7/NwXS3uND//vqwBaHJIDK2aGfmJnod+oY29LyEwpiDlg7Uxcdd/V0tyBw=="],
|
|
41
42
|
|
|
42
43
|
"@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.71.0", "", { "os": "android", "cpu": "arm" }, "sha512-l31EyBfB4egJeFua11aQFEUE9nnDtfpWCadqQovm0WL30t/yUHtdFl/5HyFXvd5xT8Ewh3U4TI9f30GowrQ1fw=="],
|
|
43
44
|
|
|
@@ -5,44 +5,113 @@ Feature: IO commands
|
|
|
5
5
|
|
|
6
6
|
Scenario: list shows a file that was written
|
|
7
7
|
Given a file "a.txt" containing "hello" in the working directory
|
|
8
|
-
When the executable stdout is captured for "list {workdir}"
|
|
8
|
+
When the executable stdout is captured for "list --location.protocol=file --location.file.path={workdir}"
|
|
9
9
|
Then the captured process should complete with exit code 0
|
|
10
10
|
And the stdout should contain "a.txt"
|
|
11
11
|
|
|
12
12
|
Scenario: get-properties reports size
|
|
13
13
|
Given a file "a.txt" containing "hello" in the working directory
|
|
14
|
-
When the executable stdout is captured for "get-properties {workdir}
|
|
14
|
+
When the executable stdout is captured for "get-properties --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt"
|
|
15
15
|
Then the captured process should complete with exit code 0
|
|
16
16
|
And the stdout should contain '"size": 5'
|
|
17
17
|
|
|
18
18
|
Scenario: set-properties reports success
|
|
19
19
|
Given a file "a.txt" containing "hello" in the working directory
|
|
20
|
-
When the executable stdout is captured for "set-properties {workdir}
|
|
20
|
+
When the executable stdout is captured for "set-properties --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt --properties.file.mode=420"
|
|
21
21
|
Then the captured process should complete with exit code 0
|
|
22
22
|
And the stdout should contain "Updated properties"
|
|
23
23
|
|
|
24
24
|
Scenario: copy duplicates a file, leaving the original in place
|
|
25
25
|
Given a file "a.txt" containing "hello" in the working directory
|
|
26
|
-
When the executable stdout is captured for "copy {workdir}
|
|
26
|
+
When the executable stdout is captured for "copy --source.protocol=file --source.file.path={workdir} --source.file.filename=a.txt --dest.protocol=file --dest.file.path={workdir} --dest.file.filename=b.txt"
|
|
27
27
|
Then the captured process should complete with exit code 0
|
|
28
28
|
And a file "b.txt" should exist in the working directory
|
|
29
29
|
And a file "a.txt" should exist in the working directory
|
|
30
|
+
And the stdout should contain "path: file/js -> file/js"
|
|
30
31
|
|
|
31
32
|
Scenario: move relocates a file
|
|
32
33
|
Given a file "a.txt" containing "hello" in the working directory
|
|
33
|
-
When the executable stdout is captured for "move {workdir}
|
|
34
|
+
When the executable stdout is captured for "move --source.protocol=file --source.file.path={workdir} --source.file.filename=a.txt --dest.protocol=file --dest.file.path={workdir} --dest.file.filename=c.txt"
|
|
34
35
|
Then the captured process should complete with exit code 0
|
|
35
36
|
And a file "c.txt" should exist in the working directory
|
|
36
37
|
And a file "a.txt" should not exist in the working directory
|
|
37
38
|
|
|
38
39
|
Scenario: delete removes a file
|
|
39
40
|
Given a file "a.txt" containing "hello" in the working directory
|
|
40
|
-
When the executable stdout is captured for "delete {workdir}
|
|
41
|
+
When the executable stdout is captured for "delete --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt"
|
|
41
42
|
Then the captured process should complete with exit code 0
|
|
42
43
|
And a file "a.txt" should not exist in the working directory
|
|
43
44
|
|
|
44
45
|
Scenario: hash outputs the expected sha256 digest
|
|
45
46
|
Given a file "a.txt" containing "hello" in the working directory
|
|
46
|
-
When the executable stdout is captured for "hash {workdir}
|
|
47
|
+
When the executable stdout is captured for "hash --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt"
|
|
47
48
|
Then the captured process should complete with exit code 0
|
|
48
49
|
And the stdout should contain "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
|
|
50
|
+
|
|
51
|
+
Scenario: copy with a pattern copies only the matching files
|
|
52
|
+
Given a file "a.txt" containing "hello" in the working directory
|
|
53
|
+
And a file "b.log" containing "hello" in the working directory
|
|
54
|
+
And a folder "out" in the working directory
|
|
55
|
+
When the executable stdout is captured for "copy --source.protocol=file --source.file.path={workdir} --source.file.pattern=*.txt --dest.protocol=file --dest.file.path={workdir}/out"
|
|
56
|
+
Then the captured process should complete with exit code 0
|
|
57
|
+
And a file "out/a.txt" should exist in the working directory
|
|
58
|
+
And a file "out/b.log" should not exist in the working directory
|
|
59
|
+
|
|
60
|
+
Scenario: list recursive descends into sub folders
|
|
61
|
+
Given a folder "sub" in the working directory
|
|
62
|
+
And a file "sub/c.log" containing "hello" in the working directory
|
|
63
|
+
When the executable stdout is captured for "list --location.protocol=file --location.file.path={workdir} --recursive"
|
|
64
|
+
Then the captured process should complete with exit code 0
|
|
65
|
+
And the stdout should contain "sub/c.log"
|
|
66
|
+
|
|
67
|
+
Scenario: list with a regex only shows the matching items
|
|
68
|
+
Given a file "a.txt" containing "hello" in the working directory
|
|
69
|
+
And a file "b.log" containing "hello" in the working directory
|
|
70
|
+
When the executable stdout is captured for "list --location.protocol=file --location.file.path={workdir} --regex=log$"
|
|
71
|
+
Then the captured process should complete with exit code 0
|
|
72
|
+
And the stdout should contain "b.log"
|
|
73
|
+
And the stdout should not contain "a.txt"
|
|
74
|
+
|
|
75
|
+
Scenario: hash outputs the expected md5 digest
|
|
76
|
+
Given a file "a.txt" containing "hello" in the working directory
|
|
77
|
+
When the executable stdout is captured for "hash --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt --algorithm=md5"
|
|
78
|
+
Then the captured process should complete with exit code 0
|
|
79
|
+
And the stdout should contain "5d41402abc4b2a76b9719d911017c592"
|
|
80
|
+
|
|
81
|
+
Scenario: get-properties fails for a missing file
|
|
82
|
+
When the executable stdout is captured for "get-properties --location.protocol=file --location.file.path={workdir} --location.file.filename=missing.txt"
|
|
83
|
+
Then the captured process should complete with exit code 3
|
|
84
|
+
And the stderr should contain "no such file or directory"
|
|
85
|
+
|
|
86
|
+
Scenario: delete fails for a missing file
|
|
87
|
+
When the executable stdout is captured for "delete --location.protocol=file --location.file.path={workdir} --location.file.filename=missing.txt"
|
|
88
|
+
Then the captured process should complete with exit code 3
|
|
89
|
+
And the stderr should contain "no such file or directory"
|
|
90
|
+
|
|
91
|
+
Scenario: copy fails for a missing source and creates no destination
|
|
92
|
+
When the executable stdout is captured for "copy --source.protocol=file --source.file.path={workdir} --source.file.filename=missing.txt --dest.protocol=file --dest.file.path={workdir} --dest.file.filename=b.txt"
|
|
93
|
+
Then the captured process should complete with exit code 3
|
|
94
|
+
And the stderr should contain "no such file or directory"
|
|
95
|
+
And a file "b.txt" should not exist in the working directory
|
|
96
|
+
|
|
97
|
+
Scenario: list rejects a single file location
|
|
98
|
+
Given a file "a.txt" containing "hello" in the working directory
|
|
99
|
+
When the executable stdout is captured for "list --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt"
|
|
100
|
+
Then the captured process should complete with exit code 3
|
|
101
|
+
And the stderr should contain "list needs a folder or pattern location"
|
|
102
|
+
|
|
103
|
+
Scenario: hash rejects a folder location
|
|
104
|
+
When the executable stdout is captured for "hash --location.protocol=file --location.file.path={workdir}"
|
|
105
|
+
Then the captured process should complete with exit code 3
|
|
106
|
+
And the stderr should contain "hash needs a single entry location"
|
|
107
|
+
|
|
108
|
+
Scenario: an unknown location protocol is rejected
|
|
109
|
+
When the executable stdout is captured for "list --location.protocol=bogus --location.file.path={workdir}"
|
|
110
|
+
Then the captured process should complete with exit code 1
|
|
111
|
+
And the stderr should contain "illegal value"
|
|
112
|
+
|
|
113
|
+
Scenario: an unknown hash algorithm is rejected
|
|
114
|
+
Given a file "a.txt" containing "hello" in the working directory
|
|
115
|
+
When the executable stdout is captured for "hash --location.protocol=file --location.file.path={workdir} --location.file.filename=a.txt --algorithm=crc"
|
|
116
|
+
Then the captured process should complete with exit code 1
|
|
117
|
+
And the stderr should contain "illegal value"
|
|
@@ -42,3 +42,9 @@ def step_impl(context, text):
|
|
|
42
42
|
text = text.replace('\\n', '\n')
|
|
43
43
|
assert text in context.subprocess_wrapper.stderr, \
|
|
44
44
|
'expected {!r} in stderr {!r}'.format(text, context.subprocess_wrapper.stderr)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@then('the stdout should not contain "{text}"')
|
|
48
|
+
def step_impl(context, text):
|
|
49
|
+
assert text not in context.subprocess_wrapper.stdout, \
|
|
50
|
+
'expected {!r} not in stdout {!r}'.format(text, context.subprocess_wrapper.stdout)
|
|
@@ -15,6 +15,11 @@ def step_impl(context, name, content):
|
|
|
15
15
|
f.write(content)
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
@given('a folder "{name}" in the working directory')
|
|
19
|
+
def step_impl(context, name):
|
|
20
|
+
os.mkdir(os.path.join(context.workdir, name))
|
|
21
|
+
|
|
22
|
+
|
|
18
23
|
@then('a file "{name}" should exist in the working directory')
|
|
19
24
|
def step_impl(context, name):
|
|
20
25
|
path = os.path.join(context.workdir, name)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/flowscripter-io-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "CLI for https://github.com/flowscripter/pluggable-io-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -21,15 +21,16 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
25
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
26
|
-
"@flowscripter/dynamic-plugin-framework": "^2.2.
|
|
27
|
-
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.
|
|
28
|
-
"@flowscripter/pluggable-io-framework": "^1.
|
|
29
|
-
"@flowscripter/pluggable-io-framework-api": "^1.1
|
|
24
|
+
"@flowscripter/dynamic-cli-framework": "^9.0.0",
|
|
25
|
+
"@flowscripter/dynamic-cli-framework-api": "^5.0.0",
|
|
26
|
+
"@flowscripter/dynamic-plugin-framework": "^2.2.19",
|
|
27
|
+
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.13",
|
|
28
|
+
"@flowscripter/pluggable-io-framework": "^2.1.0",
|
|
29
|
+
"@flowscripter/pluggable-io-framework-api": "^3.1.1",
|
|
30
|
+
"zod": "^4.6.5"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@flowscripter/io-plugin-filesystem": "^
|
|
33
|
+
"@flowscripter/io-plugin-filesystem": "^2.0.2",
|
|
33
34
|
"@types/bun": "^1.4.2",
|
|
34
35
|
"@types/node": "^26.6.3",
|
|
35
36
|
"oxfmt": "0.71.0",
|
package/src/cli.ts
CHANGED
|
@@ -4,17 +4,18 @@ import {
|
|
|
4
4
|
SyntaxHighlighterServiceProvider,
|
|
5
5
|
launchMultiCommandCLI,
|
|
6
6
|
} from "@flowscripter/dynamic-cli-framework";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
7
|
+
import { createCopyCommand } from "./commands/copy.ts";
|
|
8
|
+
import { createDeleteCommand } from "./commands/delete.ts";
|
|
9
|
+
import { createGetPropertiesCommand } from "./commands/get-properties.ts";
|
|
10
|
+
import { createHashCommand } from "./commands/hash.ts";
|
|
11
|
+
import { createListCommand } from "./commands/list.ts";
|
|
12
|
+
import { createMoveCommand } from "./commands/move.ts";
|
|
13
|
+
import { createSetPropertiesCommand } from "./commands/set-properties.ts";
|
|
14
14
|
import {
|
|
15
15
|
PLUGGABLE_IO_FRAMEWORK_PACKAGE_JSON_NAMESPACE,
|
|
16
16
|
getPluginsNodeModulesPath,
|
|
17
|
-
} from "./pluginsDir.ts";
|
|
17
|
+
} from "./util/pluginsDir.ts";
|
|
18
|
+
import { createProviderRegistry } from "./util/providerRegistry.ts";
|
|
18
19
|
import packageJson from "../package.json";
|
|
19
20
|
|
|
20
21
|
export function getCLIFeatureOptions(): BaseCLIFeatureOptions {
|
|
@@ -37,8 +38,17 @@ export function getCLIFeatureOptions(): BaseCLIFeatureOptions {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export async function cli(): Promise<void> {
|
|
41
|
+
const registry = await createProviderRegistry();
|
|
40
42
|
await launchMultiCommandCLI(
|
|
41
|
-
[
|
|
43
|
+
[
|
|
44
|
+
createListCommand(registry),
|
|
45
|
+
createGetPropertiesCommand(registry),
|
|
46
|
+
createSetPropertiesCommand(registry),
|
|
47
|
+
createDeleteCommand(registry),
|
|
48
|
+
createCopyCommand(registry),
|
|
49
|
+
createMoveCommand(registry),
|
|
50
|
+
createHashCommand(registry),
|
|
51
|
+
],
|
|
42
52
|
"Example CLI for pluggable-io-framework.",
|
|
43
53
|
"flowscripter-io-cli",
|
|
44
54
|
packageJson.version,
|
package/src/commands/copy.ts
CHANGED
|
@@ -1,63 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type Context,
|
|
5
|
-
type PrinterService,
|
|
6
|
-
type SubCommand,
|
|
7
|
-
type Values,
|
|
8
|
-
ValueTypeName,
|
|
9
|
-
} from "@flowscripter/dynamic-cli-framework";
|
|
10
|
-
import { copy as copyProvider } 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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: `Copying ${source}`,
|
|
41
|
-
total: byteScale.total,
|
|
42
|
-
format: byteScale.format,
|
|
43
|
-
formatRate: byteScale.formatRate,
|
|
44
|
-
});
|
|
45
|
-
try {
|
|
46
|
-
await copyProvider(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(`Copied ${source} to ${destination}\n`, Icon.SUCCESS);
|
|
57
|
-
} finally {
|
|
58
|
-
await provider[Symbol.asyncDispose]();
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default copy;
|
|
5
|
+
export function createCopyCommand(registry: ProviderRegistry): SubCommand {
|
|
6
|
+
return createTransferCommand(registry, "copy");
|
|
7
|
+
}
|
package/src/commands/delete.ts
CHANGED
|
@@ -5,38 +5,37 @@ import {
|
|
|
5
5
|
type PrinterService,
|
|
6
6
|
type SubCommand,
|
|
7
7
|
type Values,
|
|
8
|
-
ValueTypeName,
|
|
9
8
|
} from "@flowscripter/dynamic-cli-framework";
|
|
10
|
-
import {
|
|
9
|
+
import type { ProviderRegistry } from "@flowscripter/pluggable-io-framework";
|
|
10
|
+
import { createLocationOption } from "../util/location/createLocationOption.ts";
|
|
11
|
+
import { targetKey } from "../util/location/targetKey.ts";
|
|
12
|
+
import { toStructuredLocation } from "../util/location/toStructuredLocation.ts";
|
|
13
|
+
import { requireOperation } from "../util/requireOperation.ts";
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
options: [],
|
|
23
|
-
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
24
|
-
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
25
|
-
const path = argumentValues.path as string;
|
|
15
|
+
export function createDeleteCommand(registry: ProviderRegistry): SubCommand {
|
|
16
|
+
return {
|
|
17
|
+
name: "delete",
|
|
18
|
+
description: "Delete a file/folder",
|
|
19
|
+
positionals: [],
|
|
20
|
+
options: [createLocationOption(registry, "location", "Location to delete")],
|
|
21
|
+
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
22
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
23
|
+
const location = toStructuredLocation(argumentValues.location as Values);
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
await printerService.showSpinner(`Deleting ${path}...`);
|
|
25
|
+
const { provider, target } = await registry.createProviderForLocation(location);
|
|
30
26
|
try {
|
|
31
|
-
|
|
27
|
+
const deleteEntry = requireOperation(provider, "delete", location.protocol);
|
|
28
|
+
const key = targetKey(target, "delete");
|
|
29
|
+
await printerService.showSpinner(`Deleting ${key}...`);
|
|
30
|
+
try {
|
|
31
|
+
await deleteEntry(key);
|
|
32
|
+
} finally {
|
|
33
|
+
await printerService.hideSpinner();
|
|
34
|
+
}
|
|
35
|
+
await printerService.print(`Deleted ${key}\n`, Icon.SUCCESS);
|
|
32
36
|
} finally {
|
|
33
|
-
await
|
|
37
|
+
await provider[Symbol.asyncDispose]();
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default deleteCommand;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -8,40 +8,36 @@ import {
|
|
|
8
8
|
type SubCommand,
|
|
9
9
|
type SyntaxHighlighterService,
|
|
10
10
|
type Values,
|
|
11
|
-
ValueTypeName,
|
|
12
11
|
} from "@flowscripter/dynamic-cli-framework";
|
|
13
|
-
import {
|
|
12
|
+
import type { ProviderRegistry } from "@flowscripter/pluggable-io-framework";
|
|
13
|
+
import { createLocationOption } from "../util/location/createLocationOption.ts";
|
|
14
|
+
import { targetKey } from "../util/location/targetKey.ts";
|
|
15
|
+
import { toStructuredLocation } from "../util/location/toStructuredLocation.ts";
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
) as PrettyPrinterService;
|
|
31
|
-
const syntaxHighlighterService = context.getServiceById(
|
|
32
|
-
SYNTAX_HIGHLIGHTER_SERVICE_ID,
|
|
33
|
-
) as SyntaxHighlighterService;
|
|
34
|
-
const path = argumentValues.path as string;
|
|
35
|
-
|
|
36
|
-
const provider = await getFilesystemProvider("");
|
|
37
|
-
try {
|
|
38
|
-
const properties = await provider.getProperties(path);
|
|
39
|
-
const pretty = await prettyPrinterService.prettify(JSON.stringify(properties), "json");
|
|
40
|
-
await printerService.print(`${syntaxHighlighterService.highlight(pretty, "json")}\n`);
|
|
41
|
-
} finally {
|
|
42
|
-
await provider[Symbol.asyncDispose]();
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
17
|
+
export function createGetPropertiesCommand(registry: ProviderRegistry): SubCommand {
|
|
18
|
+
return {
|
|
19
|
+
name: "get-properties",
|
|
20
|
+
description: "Get properties of a file/folder",
|
|
21
|
+
positionals: [],
|
|
22
|
+
options: [createLocationOption(registry, "location", "Location to inspect")],
|
|
23
|
+
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
24
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
25
|
+
const prettyPrinterService = context.getServiceById(
|
|
26
|
+
PRETTY_PRINTER_SERVICE_ID,
|
|
27
|
+
) as PrettyPrinterService;
|
|
28
|
+
const syntaxHighlighterService = context.getServiceById(
|
|
29
|
+
SYNTAX_HIGHLIGHTER_SERVICE_ID,
|
|
30
|
+
) as SyntaxHighlighterService;
|
|
31
|
+
const location = toStructuredLocation(argumentValues.location as Values);
|
|
46
32
|
|
|
47
|
-
|
|
33
|
+
const { provider, target } = await registry.createProviderForLocation(location);
|
|
34
|
+
try {
|
|
35
|
+
const properties = await provider.getProperties(targetKey(target, "get-properties"));
|
|
36
|
+
const pretty = await prettyPrinterService.prettify(JSON.stringify(properties), "json");
|
|
37
|
+
await printerService.print(`${syntaxHighlighterService.highlight(pretty, "json")}\n`);
|
|
38
|
+
} finally {
|
|
39
|
+
await provider[Symbol.asyncDispose]();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|