typescript-virtual-container 1.2.8 → 1.3.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/.vscode/settings.json +0 -1
- package/README.md +462 -44
- package/biome.json +7 -0
- package/dist/SSHMimic/exec.d.ts.map +1 -1
- package/dist/SSHMimic/executor.d.ts.map +1 -1
- package/dist/SSHMimic/executor.js +35 -21
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +20 -6
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
- package/dist/VirtualFileSystem/binaryPack.js +29 -6
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +36 -13
- package/dist/VirtualPackageManager/index.d.ts +202 -0
- package/dist/VirtualPackageManager/index.d.ts.map +1 -0
- package/dist/VirtualPackageManager/index.js +825 -0
- package/dist/VirtualShell/index.d.ts +93 -12
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +95 -13
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +3 -1
- package/dist/VirtualShell/shellParser.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.d.ts +52 -20
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.js +54 -20
- package/dist/commands/adduser.d.ts +6 -0
- package/dist/commands/adduser.d.ts.map +1 -1
- package/dist/commands/adduser.js +6 -0
- package/dist/commands/alias.d.ts +9 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +63 -0
- package/dist/commands/apt.d.ts +9 -0
- package/dist/commands/apt.d.ts.map +1 -0
- package/dist/commands/apt.js +205 -0
- package/dist/commands/awk.d.ts +11 -0
- package/dist/commands/awk.d.ts.map +1 -1
- package/dist/commands/awk.js +15 -2
- package/dist/commands/base64.d.ts +5 -0
- package/dist/commands/base64.d.ts.map +1 -1
- package/dist/commands/base64.js +9 -1
- package/dist/commands/cat.d.ts +5 -0
- package/dist/commands/cat.d.ts.map +1 -1
- package/dist/commands/cat.js +35 -8
- package/dist/commands/cd.d.ts +5 -0
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +5 -0
- package/dist/commands/chmod.d.ts +5 -0
- package/dist/commands/chmod.d.ts.map +1 -1
- package/dist/commands/chmod.js +57 -3
- package/dist/commands/command-helpers.d.ts +78 -4
- package/dist/commands/command-helpers.d.ts.map +1 -1
- package/dist/commands/command-helpers.js +78 -4
- package/dist/commands/cp.d.ts +5 -0
- package/dist/commands/cp.d.ts.map +1 -1
- package/dist/commands/cp.js +5 -0
- package/dist/commands/curl.d.ts +5 -0
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +106 -26
- package/dist/commands/cut.d.ts +5 -0
- package/dist/commands/cut.d.ts.map +1 -1
- package/dist/commands/cut.js +8 -1
- package/dist/commands/date.d.ts +5 -0
- package/dist/commands/date.d.ts.map +1 -1
- package/dist/commands/date.js +7 -1
- package/dist/commands/declare.d.ts +3 -0
- package/dist/commands/declare.d.ts.map +1 -0
- package/dist/commands/declare.js +39 -0
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +5 -0
- package/dist/commands/dpkg.d.ts +9 -0
- package/dist/commands/dpkg.d.ts.map +1 -0
- package/dist/commands/dpkg.js +161 -0
- package/dist/commands/du.d.ts.map +1 -1
- package/dist/commands/du.js +8 -2
- package/dist/commands/echo.d.ts +5 -0
- package/dist/commands/echo.d.ts.map +1 -1
- package/dist/commands/echo.js +33 -12
- package/dist/commands/env.d.ts +5 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +11 -1
- package/dist/commands/exit.d.ts +5 -0
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +12 -2
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +3 -1
- package/dist/commands/find.d.ts +5 -0
- package/dist/commands/find.d.ts.map +1 -1
- package/dist/commands/find.js +5 -0
- package/dist/commands/free.d.ts +8 -0
- package/dist/commands/free.d.ts.map +1 -0
- package/dist/commands/free.js +43 -0
- package/dist/commands/grep.d.ts +5 -0
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +12 -2
- package/dist/commands/gzip.d.ts +5 -0
- package/dist/commands/gzip.d.ts.map +1 -1
- package/dist/commands/gzip.js +18 -2
- package/dist/commands/head.d.ts +5 -0
- package/dist/commands/head.d.ts.map +1 -1
- package/dist/commands/head.js +5 -0
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +98 -45
- package/dist/commands/helpers.d.ts +3 -0
- package/dist/commands/helpers.d.ts.map +1 -1
- package/dist/commands/helpers.js +3 -0
- package/dist/commands/history.d.ts +8 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +26 -0
- package/dist/commands/hostname.d.ts +5 -0
- package/dist/commands/hostname.d.ts.map +1 -1
- package/dist/commands/hostname.js +5 -0
- package/dist/commands/id.d.ts.map +1 -1
- package/dist/commands/id.js +4 -1
- package/dist/commands/index.d.ts +2 -10
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -231
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +6 -3
- package/dist/commands/lsb-release.d.ts +3 -0
- package/dist/commands/lsb-release.d.ts.map +1 -0
- package/dist/commands/lsb-release.js +56 -0
- package/dist/commands/man.d.ts +3 -0
- package/dist/commands/man.d.ts.map +1 -0
- package/dist/commands/man.js +155 -0
- package/dist/commands/nano.js +1 -1
- package/dist/commands/neofetch.d.ts.map +1 -1
- package/dist/commands/neofetch.js +6 -1
- package/dist/commands/node.d.ts +9 -0
- package/dist/commands/node.d.ts.map +1 -0
- package/dist/commands/node.js +316 -0
- package/dist/commands/npm.d.ts +19 -0
- package/dist/commands/npm.d.ts.map +1 -0
- package/dist/commands/npm.js +109 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +7 -2
- package/dist/commands/printf.d.ts +3 -0
- package/dist/commands/printf.d.ts.map +1 -0
- package/dist/commands/printf.js +113 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +30 -6
- package/dist/commands/python.d.ts +30 -0
- package/dist/commands/python.d.ts.map +1 -0
- package/dist/commands/python.js +2058 -0
- package/dist/commands/read.d.ts +3 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +34 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +229 -0
- package/dist/commands/runtime.d.ts +6 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +280 -0
- package/dist/commands/sed.d.ts.map +1 -1
- package/dist/commands/sed.js +11 -3
- package/dist/commands/set.d.ts.map +1 -1
- package/dist/commands/set.js +9 -3
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +69 -30
- package/dist/commands/shift.d.ts +5 -0
- package/dist/commands/shift.d.ts.map +1 -0
- package/dist/commands/shift.js +52 -0
- package/dist/commands/sleep.d.ts.map +1 -1
- package/dist/commands/sort.d.ts.map +1 -1
- package/dist/commands/sort.js +4 -2
- package/dist/commands/source.d.ts +3 -0
- package/dist/commands/source.d.ts.map +1 -0
- package/dist/commands/source.js +34 -0
- package/dist/commands/sudo.js +1 -1
- package/dist/commands/tar.d.ts.map +1 -1
- package/dist/commands/tar.js +11 -3
- package/dist/commands/tee.d.ts.map +1 -1
- package/dist/commands/tee.js +8 -6
- package/dist/commands/test.d.ts +3 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +114 -0
- package/dist/commands/tr.d.ts.map +1 -1
- package/dist/commands/tr.js +3 -1
- package/dist/commands/true.d.ts +4 -0
- package/dist/commands/true.d.ts.map +1 -0
- package/dist/commands/true.js +14 -0
- package/dist/commands/type.d.ts +3 -0
- package/dist/commands/type.d.ts.map +1 -0
- package/dist/commands/type.js +34 -0
- package/dist/commands/uname.d.ts.map +1 -1
- package/dist/commands/uname.js +4 -1
- package/dist/commands/uniq.d.ts.map +1 -1
- package/dist/commands/uptime.d.ts +3 -0
- package/dist/commands/uptime.d.ts.map +1 -0
- package/dist/commands/uptime.js +43 -0
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +92 -96
- package/dist/commands/which.d.ts +3 -0
- package/dist/commands/which.d.ts.map +1 -0
- package/dist/commands/which.js +32 -0
- package/dist/commands/xargs.d.ts.map +1 -1
- package/dist/commands/xargs.js +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/modules/linuxRootfs.d.ts +41 -0
- package/dist/modules/linuxRootfs.d.ts.map +1 -0
- package/dist/modules/linuxRootfs.js +440 -0
- package/dist/modules/neofetch.d.ts.map +1 -1
- package/dist/modules/neofetch.js +1 -0
- package/dist/standalone-wo-sftp.d.ts +2 -0
- package/dist/standalone-wo-sftp.d.ts.map +1 -0
- package/dist/standalone-wo-sftp.js +30 -0
- package/dist/utils/expand.d.ts +50 -0
- package/dist/utils/expand.d.ts.map +1 -0
- package/dist/utils/expand.js +183 -0
- package/dist/utils/vfsDiff.d.ts +90 -0
- package/dist/utils/vfsDiff.d.ts.map +1 -0
- package/dist/utils/vfsDiff.js +177 -0
- package/package.json +3 -1
- package/src/SSHMimic/exec.ts +10 -1
- package/src/SSHMimic/executor.ts +105 -21
- package/src/SSHMimic/index.ts +49 -15
- package/src/VirtualFileSystem/binaryPack.ts +35 -8
- package/src/VirtualFileSystem/index.ts +78 -28
- package/src/VirtualPackageManager/index.ts +979 -0
- package/src/VirtualShell/index.ts +133 -14
- package/src/VirtualShell/shell.ts +23 -3
- package/src/VirtualShell/shellParser.ts +134 -36
- package/src/VirtualUserManager/index.ts +62 -22
- package/src/commands/adduser.ts +6 -0
- package/src/commands/alias.ts +64 -0
- package/src/commands/apt.ts +228 -0
- package/src/commands/awk.ts +20 -6
- package/src/commands/base64.ts +13 -2
- package/src/commands/cat.ts +40 -8
- package/src/commands/cd.ts +5 -0
- package/src/commands/chmod.ts +53 -3
- package/src/commands/command-helpers.ts +78 -4
- package/src/commands/cp.ts +5 -0
- package/src/commands/curl.ts +118 -33
- package/src/commands/cut.ts +8 -1
- package/src/commands/date.ts +7 -1
- package/src/commands/declare.ts +44 -0
- package/src/commands/diff.ts +17 -3
- package/src/commands/dpkg.ts +180 -0
- package/src/commands/du.ts +17 -5
- package/src/commands/echo.ts +41 -12
- package/src/commands/env.ts +11 -1
- package/src/commands/exit.ts +12 -2
- package/src/commands/export.ts +3 -1
- package/src/commands/find.ts +5 -0
- package/src/commands/free.ts +47 -0
- package/src/commands/grep.ts +12 -2
- package/src/commands/gzip.ts +28 -4
- package/src/commands/head.ts +5 -0
- package/src/commands/help.ts +121 -47
- package/src/commands/helpers.ts +8 -0
- package/src/commands/history.ts +34 -0
- package/src/commands/hostname.ts +5 -0
- package/src/commands/id.ts +4 -1
- package/src/commands/index.ts +9 -255
- package/src/commands/ls.ts +6 -3
- package/src/commands/lsb-release.ts +58 -0
- package/src/commands/man.ts +166 -0
- package/src/commands/nano.ts +1 -1
- package/src/commands/neofetch.ts +6 -1
- package/src/commands/node.ts +341 -0
- package/src/commands/npm.ts +132 -0
- package/src/commands/ping.ts +10 -3
- package/src/commands/printf.ts +112 -0
- package/src/commands/ps.ts +40 -6
- package/src/commands/python.ts +2229 -0
- package/src/commands/read.ts +41 -0
- package/src/commands/registry.ts +244 -0
- package/src/commands/runtime.ts +353 -0
- package/src/commands/sed.ts +27 -9
- package/src/commands/set.ts +9 -3
- package/src/commands/sh.ts +170 -44
- package/src/commands/shift.ts +53 -0
- package/src/commands/sleep.ts +2 -1
- package/src/commands/sort.ts +10 -6
- package/src/commands/source.ts +47 -0
- package/src/commands/sudo.ts +1 -1
- package/src/commands/tar.ts +28 -7
- package/src/commands/tee.ts +7 -1
- package/src/commands/test.ts +135 -0
- package/src/commands/tr.ts +3 -1
- package/src/commands/true.ts +17 -0
- package/src/commands/type.ts +43 -0
- package/src/commands/uname.ts +5 -1
- package/src/commands/uniq.ts +8 -2
- package/src/commands/uptime.ts +49 -0
- package/src/commands/wget.ts +105 -119
- package/src/commands/which.ts +37 -0
- package/src/commands/xargs.ts +11 -2
- package/src/index.ts +27 -18
- package/src/modules/linuxRootfs.ts +642 -0
- package/src/modules/neofetch.ts +1 -0
- package/src/standalone-wo-sftp.ts +38 -0
- package/src/utils/expand.ts +238 -0
- package/src/utils/vfsDiff.ts +275 -0
- package/standalone-wo-sftp.js +507 -0
- package/standalone-wo-sftp.js.map +7 -0
- package/standalone.js +486 -109
- package/standalone.js.map +4 -4
- package/tests/bun-test-shim.ts +9 -1
- package/tests/command-helpers.test.ts +1 -5
- package/tests/new-features.test.ts +1036 -0
- package/tests/parser-executor.test.ts +27 -27
- package/tests/sftp.test.ts +122 -42
- package/tests/users.test.ts +23 -5
- package/CHANGELOG.md +0 -150
package/src/commands/curl.ts
CHANGED
|
@@ -1,61 +1,146 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
|
-
import { parseArgs } from "./command-helpers";
|
|
3
|
-
import {
|
|
4
|
-
assertPathAccess,
|
|
5
|
-
normalizeTerminalOutput,
|
|
6
|
-
resolvePath,
|
|
7
|
-
runHostCommand,
|
|
8
|
-
} from "./helpers";
|
|
2
|
+
import { ifFlag, parseArgs } from "./command-helpers";
|
|
3
|
+
import { assertPathAccess, resolvePath } from "./helpers";
|
|
9
4
|
|
|
5
|
+
/**
|
|
6
|
+
* HTTP client wrapper using `fetch()` semantics (virtual curl).
|
|
7
|
+
* @category network
|
|
8
|
+
* @params ["[options] <url>"]
|
|
9
|
+
*/
|
|
10
10
|
export const curlCommand: ShellModule = {
|
|
11
11
|
name: "curl",
|
|
12
|
-
description: "
|
|
12
|
+
description: "Transfer data from or to a server (pure fetch)",
|
|
13
13
|
category: "network",
|
|
14
|
-
params: ["[
|
|
14
|
+
params: ["[options] <url>"],
|
|
15
15
|
run: async ({ authUser, cwd, args, shell }) => {
|
|
16
16
|
const { flagsWithValues, positionals } = parseArgs(args, {
|
|
17
|
-
flagsWithValue: [
|
|
17
|
+
flagsWithValue: [
|
|
18
|
+
"-o",
|
|
19
|
+
"--output",
|
|
20
|
+
"-X",
|
|
21
|
+
"--request",
|
|
22
|
+
"-d",
|
|
23
|
+
"--data",
|
|
24
|
+
"-H",
|
|
25
|
+
"--header",
|
|
26
|
+
"-u",
|
|
27
|
+
"--user",
|
|
28
|
+
],
|
|
18
29
|
});
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
|
|
31
|
+
if (ifFlag(args, ["--help", "-h"])) {
|
|
32
|
+
return {
|
|
33
|
+
stdout: [
|
|
34
|
+
"Usage: curl [options] <url>",
|
|
35
|
+
" -o, --output <file> Write to file",
|
|
36
|
+
" -X, --request <method> HTTP method",
|
|
37
|
+
" -d, --data <data> POST data",
|
|
38
|
+
" -H, --header <hdr> Extra header",
|
|
39
|
+
" -s, --silent Silent mode",
|
|
40
|
+
" -I, --head Fetch headers only",
|
|
41
|
+
" -L, --location Follow redirects",
|
|
42
|
+
" -v, --verbose Verbose",
|
|
43
|
+
].join("\n"),
|
|
44
|
+
exitCode: 0,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
21
48
|
const url = positionals[0];
|
|
49
|
+
if (!url) return { stderr: "curl: no URL specified", exitCode: 1 };
|
|
50
|
+
|
|
51
|
+
const outputPath =
|
|
52
|
+
flagsWithValues.get("-o") ?? flagsWithValues.get("--output") ?? null;
|
|
53
|
+
const method = (
|
|
54
|
+
flagsWithValues.get("-X") ??
|
|
55
|
+
flagsWithValues.get("--request") ??
|
|
56
|
+
"GET"
|
|
57
|
+
).toUpperCase();
|
|
58
|
+
const postData =
|
|
59
|
+
flagsWithValues.get("-d") ?? flagsWithValues.get("--data") ?? null;
|
|
60
|
+
const headerRaw =
|
|
61
|
+
flagsWithValues.get("-H") ?? flagsWithValues.get("--header") ?? null;
|
|
62
|
+
const silent = ifFlag(args, ["-s", "--silent"]);
|
|
63
|
+
const headOnly = ifFlag(args, ["-I", "--head"]);
|
|
64
|
+
const followRedirects = ifFlag(args, ["-L", "--location"]);
|
|
65
|
+
const verbose = ifFlag(args, ["-v", "--verbose"]);
|
|
22
66
|
|
|
23
|
-
|
|
24
|
-
|
|
67
|
+
const extraHeaders: Record<string, string> = {
|
|
68
|
+
"User-Agent": "curl/7.88.1",
|
|
69
|
+
};
|
|
70
|
+
if (headerRaw) {
|
|
71
|
+
const idx = headerRaw.indexOf(":");
|
|
72
|
+
if (idx !== -1)
|
|
73
|
+
extraHeaders[headerRaw.slice(0, idx).trim()] = headerRaw
|
|
74
|
+
.slice(idx + 1)
|
|
75
|
+
.trim();
|
|
25
76
|
}
|
|
26
77
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
:
|
|
30
|
-
|
|
78
|
+
const finalMethod = postData && method === "GET" ? "POST" : method;
|
|
79
|
+
const fetchOpts: RequestInit = {
|
|
80
|
+
method: finalMethod,
|
|
81
|
+
headers: extraHeaders,
|
|
82
|
+
redirect: followRedirects ? "follow" : "manual",
|
|
83
|
+
};
|
|
84
|
+
if (postData) {
|
|
85
|
+
extraHeaders["Content-Type"] ??= "application/x-www-form-urlencoded";
|
|
86
|
+
fetchOpts.body = postData;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const stderrLines: string[] = [];
|
|
90
|
+
if (verbose) {
|
|
91
|
+
stderrLines.push(`* Trying ${url}...`, `* Connected`);
|
|
92
|
+
stderrLines.push(
|
|
93
|
+
`> ${finalMethod} / HTTP/1.1`,
|
|
94
|
+
`> Host: ${new URL(url).host}`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
31
97
|
|
|
32
|
-
|
|
98
|
+
let response: Response;
|
|
99
|
+
try {
|
|
100
|
+
response = await fetch(url, fetchOpts);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
33
103
|
return {
|
|
34
|
-
stderr:
|
|
35
|
-
|
|
36
|
-
),
|
|
37
|
-
exitCode: result.exitCode,
|
|
104
|
+
stderr: `curl: (6) Could not resolve host: ${msg}`,
|
|
105
|
+
exitCode: 6,
|
|
38
106
|
};
|
|
39
107
|
}
|
|
40
108
|
|
|
109
|
+
if (verbose) {
|
|
110
|
+
stderrLines.push(`< HTTP/1.1 ${response.status} ${response.statusText}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (headOnly) {
|
|
114
|
+
const lines = [`HTTP/1.1 ${response.status} ${response.statusText}`];
|
|
115
|
+
for (const [k, v] of response.headers.entries()) lines.push(`${k}: ${v}`);
|
|
116
|
+
return { stdout: `${lines.join("\r\n")}\r\n`, exitCode: 0 };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let body: string;
|
|
120
|
+
try {
|
|
121
|
+
body = await response.text();
|
|
122
|
+
} catch {
|
|
123
|
+
return { stderr: "curl: failed to read response body", exitCode: 1 };
|
|
124
|
+
}
|
|
125
|
+
|
|
41
126
|
if (outputPath) {
|
|
42
127
|
const target = resolvePath(cwd, outputPath);
|
|
43
128
|
assertPathAccess(authUser, target, "curl");
|
|
44
|
-
shell.writeFileAsUser(authUser, target,
|
|
129
|
+
shell.writeFileAsUser(authUser, target, body);
|
|
130
|
+
if (!silent)
|
|
131
|
+
stderrLines.push(
|
|
132
|
+
` % Total % Received\n100 ${body.length} 100 ${body.length}`,
|
|
133
|
+
);
|
|
45
134
|
return {
|
|
46
|
-
stderr:
|
|
47
|
-
|
|
48
|
-
: undefined,
|
|
49
|
-
exitCode: 0,
|
|
135
|
+
stderr: stderrLines.join("\n") || undefined,
|
|
136
|
+
exitCode: response.ok ? 0 : 22,
|
|
50
137
|
};
|
|
51
138
|
}
|
|
52
139
|
|
|
53
140
|
return {
|
|
54
|
-
stdout:
|
|
55
|
-
stderr:
|
|
56
|
-
|
|
57
|
-
: undefined,
|
|
58
|
-
exitCode: 0,
|
|
141
|
+
stdout: body,
|
|
142
|
+
stderr: stderrLines.length > 0 ? stderrLines.join("\n") : undefined,
|
|
143
|
+
exitCode: response.ok ? 0 : 22,
|
|
59
144
|
};
|
|
60
145
|
},
|
|
61
146
|
};
|
package/src/commands/cut.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
2
|
import { getFlag } from "./command-helpers";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Extract selected fields from each line of input.
|
|
6
|
+
* @category text
|
|
7
|
+
* @params ["-d <delim> -f <fields> [file]"]
|
|
8
|
+
*/
|
|
4
9
|
export const cutCommand: ShellModule = {
|
|
5
10
|
name: "cut",
|
|
6
11
|
description: "Remove sections from lines",
|
|
@@ -11,7 +16,9 @@ export const cutCommand: ShellModule = {
|
|
|
11
16
|
const fields = (getFlag(args, ["-f"]) as string | undefined) ?? "1";
|
|
12
17
|
const cols = fields.split(",").map((f) => {
|
|
13
18
|
const [a, b] = f.split("-").map(Number);
|
|
14
|
-
return b !== undefined
|
|
19
|
+
return b !== undefined
|
|
20
|
+
? { from: (a ?? 1) - 1, to: b - 1 }
|
|
21
|
+
: { from: (a ?? 1) - 1, to: (a ?? 1) - 1 };
|
|
15
22
|
});
|
|
16
23
|
const lines = (stdin ?? "").split("\n");
|
|
17
24
|
const out = lines.map((line) => {
|
package/src/commands/date.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Print the current date/time or a formatted representation.
|
|
5
|
+
* @category system
|
|
6
|
+
* @params ["[+format]"]
|
|
7
|
+
*/
|
|
3
8
|
export const dateCommand: ShellModule = {
|
|
4
9
|
name: "date",
|
|
5
10
|
description: "Print current date and time",
|
|
@@ -9,7 +14,8 @@ export const dateCommand: ShellModule = {
|
|
|
9
14
|
const now = new Date();
|
|
10
15
|
const fmt = args[0];
|
|
11
16
|
if (fmt?.startsWith("+")) {
|
|
12
|
-
const f = fmt
|
|
17
|
+
const f = fmt
|
|
18
|
+
.slice(1)
|
|
13
19
|
.replace("%Y", String(now.getFullYear()))
|
|
14
20
|
.replace("%m", String(now.getMonth() + 1).padStart(2, "0"))
|
|
15
21
|
.replace("%d", String(now.getDate()).padStart(2, "0"))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ShellModule } from "../types/commands";
|
|
2
|
+
import { ifFlag } from "./command-helpers";
|
|
3
|
+
|
|
4
|
+
export const declareCommand: ShellModule = {
|
|
5
|
+
name: "declare",
|
|
6
|
+
aliases: ["local", "typeset"],
|
|
7
|
+
description: "Declare variables and give them attributes",
|
|
8
|
+
category: "shell",
|
|
9
|
+
params: ["[-i] [-r] [-x] [-a] [name[=value]...]"],
|
|
10
|
+
run: ({ args, env }) => {
|
|
11
|
+
if (!env) return { exitCode: 0 };
|
|
12
|
+
|
|
13
|
+
const integer = ifFlag(args, ["-i"]);
|
|
14
|
+
const _readonly = ifFlag(args, ["-r"]);
|
|
15
|
+
const _export_ = ifFlag(args, ["-x"]);
|
|
16
|
+
const printAll = args.filter((a) => !a.startsWith("-")).length === 0;
|
|
17
|
+
|
|
18
|
+
if (printAll) {
|
|
19
|
+
const lines = Object.entries(env.vars).map(
|
|
20
|
+
([k, v]) => `declare -- ${k}="${v}"`,
|
|
21
|
+
);
|
|
22
|
+
return { stdout: lines.join("\n"), exitCode: 0 };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const assignments = args.filter((a) => !a.startsWith("-"));
|
|
26
|
+
for (const token of assignments) {
|
|
27
|
+
const eq = token.indexOf("=");
|
|
28
|
+
if (eq === -1) {
|
|
29
|
+
// Just declare (no value)
|
|
30
|
+
if (!(token in env.vars)) env.vars[token] = "";
|
|
31
|
+
} else {
|
|
32
|
+
const name = token.slice(0, eq);
|
|
33
|
+
let val = token.slice(eq + 1);
|
|
34
|
+
if (integer) {
|
|
35
|
+
const n = parseInt(val, 10);
|
|
36
|
+
val = Number.isNaN(n) ? "0" : String(n);
|
|
37
|
+
}
|
|
38
|
+
env.vars[name] = val;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { exitCode: 0 };
|
|
43
|
+
},
|
|
44
|
+
};
|
package/src/commands/diff.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
2
|
import { resolvePath } from "./helpers";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Compare files line-by-line and print differing lines.
|
|
6
|
+
* @category text
|
|
7
|
+
* @params ["<file1> <file2>"]
|
|
8
|
+
*/
|
|
4
9
|
export const diffCommand: ShellModule = {
|
|
5
10
|
name: "diff",
|
|
6
11
|
description: "Compare files line by line",
|
|
@@ -12,13 +17,22 @@ export const diffCommand: ShellModule = {
|
|
|
12
17
|
const p1 = resolvePath(cwd, f1);
|
|
13
18
|
const p2 = resolvePath(cwd, f2);
|
|
14
19
|
let a: string[], b: string[];
|
|
15
|
-
try {
|
|
16
|
-
|
|
20
|
+
try {
|
|
21
|
+
a = shell.vfs.readFile(p1).split("\n");
|
|
22
|
+
} catch {
|
|
23
|
+
return { stderr: `diff: ${f1}: No such file or directory`, exitCode: 2 };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
b = shell.vfs.readFile(p2).split("\n");
|
|
27
|
+
} catch {
|
|
28
|
+
return { stderr: `diff: ${f2}: No such file or directory`, exitCode: 2 };
|
|
29
|
+
}
|
|
17
30
|
|
|
18
31
|
const out: string[] = [];
|
|
19
32
|
const max = Math.max(a.length, b.length);
|
|
20
33
|
for (let i = 0; i < max; i++) {
|
|
21
|
-
const la = a[i];
|
|
34
|
+
const la = a[i];
|
|
35
|
+
const lb = b[i];
|
|
22
36
|
if (la !== lb) {
|
|
23
37
|
if (la !== undefined) out.push(`< ${la}`);
|
|
24
38
|
if (lb !== undefined) out.push(`> ${lb}`);
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { ShellModule } from "../types/commands";
|
|
2
|
+
import { ifFlag, parseArgs } from "./command-helpers";
|
|
3
|
+
import { getPackageManager } from "./helpers";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* dpkg compatibility command (query/remove/list) backed by the virtual package manager.
|
|
7
|
+
* @category package
|
|
8
|
+
* @params ["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"]
|
|
9
|
+
*/
|
|
10
|
+
export const dpkgCommand: ShellModule = {
|
|
11
|
+
name: "dpkg",
|
|
12
|
+
description: "Debian package manager low-level tool",
|
|
13
|
+
category: "package",
|
|
14
|
+
params: ["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],
|
|
15
|
+
run: ({ args, authUser, shell }) => {
|
|
16
|
+
const pm = getPackageManager(shell);
|
|
17
|
+
if (!pm)
|
|
18
|
+
return { stderr: "dpkg: package manager not initialised", exitCode: 1 };
|
|
19
|
+
|
|
20
|
+
const listFlag = ifFlag(args, ["-l", "--list"]);
|
|
21
|
+
const statusFlag = ifFlag(args, ["-s", "--status"]);
|
|
22
|
+
const listFilesFlag = ifFlag(args, ["-L", "--listfiles"]);
|
|
23
|
+
const removeFlag = ifFlag(args, ["-r", "--remove"]);
|
|
24
|
+
const purgeFlag = ifFlag(args, ["-P", "--purge"]);
|
|
25
|
+
|
|
26
|
+
const { positionals } = parseArgs(args, {
|
|
27
|
+
flags: [
|
|
28
|
+
"-l",
|
|
29
|
+
"--list",
|
|
30
|
+
"-s",
|
|
31
|
+
"--status",
|
|
32
|
+
"-L",
|
|
33
|
+
"--listfiles",
|
|
34
|
+
"-r",
|
|
35
|
+
"--remove",
|
|
36
|
+
"-P",
|
|
37
|
+
"--purge",
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (listFlag) {
|
|
42
|
+
const pkgList = pm.listInstalled();
|
|
43
|
+
if (pkgList.length === 0) {
|
|
44
|
+
return {
|
|
45
|
+
stdout: [
|
|
46
|
+
"Desired=Unknown/Install/Remove/Purge/Hold",
|
|
47
|
+
"|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend",
|
|
48
|
+
"|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)",
|
|
49
|
+
"||/ Name Version Architecture Description",
|
|
50
|
+
"+++-==============-===============-============-========================================",
|
|
51
|
+
"(no packages installed)",
|
|
52
|
+
].join("\n"),
|
|
53
|
+
exitCode: 0,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const header = [
|
|
58
|
+
"Desired=Unknown/Install/Remove/Purge/Hold",
|
|
59
|
+
"|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend",
|
|
60
|
+
"|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)",
|
|
61
|
+
"||/ Name Version Architecture Description",
|
|
62
|
+
"+++-==============-===============-============-========================================",
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const rows = pkgList.map((p) => {
|
|
66
|
+
const name = p.name.padEnd(14).slice(0, 14);
|
|
67
|
+
const ver = p.version.padEnd(15).slice(0, 15);
|
|
68
|
+
const arch = p.architecture.padEnd(12).slice(0, 12);
|
|
69
|
+
const desc = (p.description || "").slice(0, 40);
|
|
70
|
+
return `ii ${name} ${ver} ${arch} ${desc}`;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return { stdout: [...header, ...rows].join("\n"), exitCode: 0 };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (statusFlag) {
|
|
77
|
+
const pkgName = positionals[0];
|
|
78
|
+
if (!pkgName)
|
|
79
|
+
return { stderr: "dpkg: -s needs a package name", exitCode: 1 };
|
|
80
|
+
const info = pm.show(pkgName);
|
|
81
|
+
if (!info)
|
|
82
|
+
return {
|
|
83
|
+
stderr: `dpkg-query: package '${pkgName}' is not installed and no information is available`,
|
|
84
|
+
exitCode: 1,
|
|
85
|
+
};
|
|
86
|
+
return { stdout: info, exitCode: 0 };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (listFilesFlag) {
|
|
90
|
+
const pkgName = positionals[0];
|
|
91
|
+
if (!pkgName)
|
|
92
|
+
return { stderr: "dpkg: -L needs a package name", exitCode: 1 };
|
|
93
|
+
const installed = pm.listInstalled().find((p) => p.name === pkgName);
|
|
94
|
+
if (!installed)
|
|
95
|
+
return {
|
|
96
|
+
stderr: `dpkg-query: package '${pkgName}' is not installed`,
|
|
97
|
+
exitCode: 1,
|
|
98
|
+
};
|
|
99
|
+
if (installed.files.length === 0)
|
|
100
|
+
return { stdout: "/.keep", exitCode: 0 };
|
|
101
|
+
return { stdout: installed.files.join("\n"), exitCode: 0 };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (removeFlag || purgeFlag) {
|
|
105
|
+
if (authUser !== "root")
|
|
106
|
+
return {
|
|
107
|
+
stderr:
|
|
108
|
+
"dpkg: error: requested operation requires superuser privilege",
|
|
109
|
+
exitCode: 2,
|
|
110
|
+
};
|
|
111
|
+
if (positionals.length === 0)
|
|
112
|
+
return { stderr: "dpkg: error: need an action option", exitCode: 2 };
|
|
113
|
+
const { output, exitCode } = pm.remove(positionals, { purge: purgeFlag });
|
|
114
|
+
return { stdout: output || undefined, exitCode };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Default: show help
|
|
118
|
+
return {
|
|
119
|
+
stdout: [
|
|
120
|
+
"Usage: dpkg [<option>...] <command>",
|
|
121
|
+
"",
|
|
122
|
+
"Commands:",
|
|
123
|
+
" -l, --list List packages matching given pattern",
|
|
124
|
+
" -s, --status <pkg>... Report status of specified package",
|
|
125
|
+
" -L, --listfiles <pkg>... List files owned by package",
|
|
126
|
+
" -r, --remove <pkg>... Remove <pkg> but leave its configuration",
|
|
127
|
+
" -P, --purge <pkg>... Remove <pkg> and its configuration",
|
|
128
|
+
].join("\n"),
|
|
129
|
+
exitCode: 0,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const dpkgQueryCommand: ShellModule = {
|
|
135
|
+
name: "dpkg-query",
|
|
136
|
+
description: "Show information about installed packages",
|
|
137
|
+
category: "package",
|
|
138
|
+
params: ["-W [pkg] | -l [pattern]"],
|
|
139
|
+
run: ({ args, shell }) => {
|
|
140
|
+
const pm = getPackageManager(shell);
|
|
141
|
+
if (!pm)
|
|
142
|
+
return {
|
|
143
|
+
stderr: "dpkg-query: package manager not initialised",
|
|
144
|
+
exitCode: 1,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const listFlag = ifFlag(args, ["-l"]);
|
|
148
|
+
const showFlag = ifFlag(args, ["-W", "--show"]);
|
|
149
|
+
const { positionals } = parseArgs(args, {
|
|
150
|
+
flags: ["-l", "-W", "--show"],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (listFlag || showFlag) {
|
|
154
|
+
const pkgList = pm.listInstalled();
|
|
155
|
+
const pattern = positionals[0];
|
|
156
|
+
const filtered = pattern
|
|
157
|
+
? pkgList.filter((p) => p.name.includes(pattern))
|
|
158
|
+
: pkgList;
|
|
159
|
+
|
|
160
|
+
if (showFlag) {
|
|
161
|
+
return {
|
|
162
|
+
stdout: filtered.map((p) => `${p.name}\t${p.version}`).join("\n"),
|
|
163
|
+
exitCode: 0,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const rows = filtered.map((p) => {
|
|
168
|
+
const name = p.name.padEnd(14).slice(0, 14);
|
|
169
|
+
const ver = p.version.padEnd(15).slice(0, 15);
|
|
170
|
+
return `ii ${name} ${ver} amd64 ${(p.description || "").slice(0, 40)}`;
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
stdout: rows.join("\n") || "(no packages match)",
|
|
174
|
+
exitCode: 0,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return { stderr: "dpkg-query: need a flag (-l, -W)", exitCode: 1 };
|
|
179
|
+
},
|
|
180
|
+
};
|
package/src/commands/du.ts
CHANGED
|
@@ -13,22 +13,34 @@ export const duCommand: ShellModule = {
|
|
|
13
13
|
const target = args.find((a) => !a.startsWith("-")) ?? ".";
|
|
14
14
|
const p = resolvePath(cwd, target);
|
|
15
15
|
|
|
16
|
-
const fmt = (b: number) =>
|
|
16
|
+
const fmt = (b: number) =>
|
|
17
|
+
human ? `${(b / 1024).toFixed(1)}K` : String(Math.ceil(b / 1024));
|
|
17
18
|
|
|
18
|
-
if (!shell.vfs.exists(p))
|
|
19
|
+
if (!shell.vfs.exists(p))
|
|
20
|
+
return {
|
|
21
|
+
stderr: `du: ${target}: No such file or directory`,
|
|
22
|
+
exitCode: 1,
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
if (summary || shell.vfs.stat(p).type === "file") {
|
|
21
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
stdout: `${fmt(shell.vfs.getUsageBytes(p))}\t${target}`,
|
|
28
|
+
exitCode: 0,
|
|
29
|
+
};
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
const lines: string[] = [];
|
|
25
33
|
const walk = (dir: string, rel: string) => {
|
|
26
34
|
let total = 0;
|
|
27
35
|
for (const e of shell.vfs.list(dir)) {
|
|
28
|
-
const full = `${dir}/${e}`,
|
|
36
|
+
const full = `${dir}/${e}`,
|
|
37
|
+
r = `${rel}/${e}`;
|
|
29
38
|
const st = shell.vfs.stat(full);
|
|
30
39
|
if (st.type === "directory") total += walk(full, r);
|
|
31
|
-
else {
|
|
40
|
+
else {
|
|
41
|
+
total += st.size;
|
|
42
|
+
if (!summary) lines.push(`${fmt(st.size)}\t${r}`);
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
45
|
lines.push(`${fmt(total)}\t${rel}`);
|
|
34
46
|
return total;
|
package/src/commands/echo.ts
CHANGED
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
2
|
import { parseArgs } from "./command-helpers";
|
|
3
|
-
import {
|
|
3
|
+
import { expandSync } from "../utils/expand";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Expand escape sequences for `echo -e`.
|
|
7
|
+
* Handles \n \t \r \\ \a \b \f \v and \0NNN (octal).
|
|
8
|
+
*/
|
|
9
|
+
function expandEscapes(text: string): string {
|
|
10
|
+
return text
|
|
11
|
+
.replace(/\\n/g, "\n")
|
|
12
|
+
.replace(/\\t/g, "\t")
|
|
13
|
+
.replace(/\\r/g, "\r")
|
|
14
|
+
.replace(/\\\\/g, "\\")
|
|
15
|
+
.replace(/\\a/g, "\x07")
|
|
16
|
+
.replace(/\\b/g, "\x08")
|
|
17
|
+
.replace(/\\f/g, "\x0C")
|
|
18
|
+
.replace(/\\v/g, "\x0B")
|
|
19
|
+
.replace(/\\0(\d{1,3})/g, (_, oct) =>
|
|
20
|
+
String.fromCharCode(parseInt(oct, 8)),
|
|
21
|
+
);
|
|
9
22
|
}
|
|
10
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Echo text to stdout with shell-style expansion and escape support.
|
|
26
|
+
* @category shell
|
|
27
|
+
* @params ["[-n] [-e] [text...]"]
|
|
28
|
+
*/
|
|
11
29
|
export const echoCommand: ShellModule = {
|
|
12
30
|
name: "echo",
|
|
13
31
|
description: "Display text",
|
|
14
32
|
category: "shell",
|
|
15
|
-
params: ["[
|
|
16
|
-
run: ({ args,
|
|
17
|
-
const { flags, positionals } = parseArgs(args, {
|
|
18
|
-
|
|
33
|
+
params: ["[-n] [-e] [text...]"],
|
|
34
|
+
run: ({ args, stdin, env }) => {
|
|
35
|
+
const { flags, positionals } = parseArgs(args, {
|
|
36
|
+
flags: ["-n", "-e", "-E"],
|
|
37
|
+
});
|
|
38
|
+
const noNewline = flags.has("-n");
|
|
39
|
+
const escapes = flags.has("-e");
|
|
40
|
+
|
|
19
41
|
const rawText =
|
|
20
42
|
positionals.length > 0 ? positionals.join(" ") : (stdin ?? "");
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
|
|
44
|
+
// Full expansion: $? ${#VAR} $((expr)) ~ ${VAR:-def} $VAR etc.
|
|
45
|
+
// $(cmd) is already resolved upstream by runCommand before echo.run is called.
|
|
46
|
+
const expanded = expandSync(
|
|
47
|
+
rawText,
|
|
48
|
+
env?.vars ?? {},
|
|
49
|
+
env?.lastExitCode ?? 0,
|
|
50
|
+
);
|
|
51
|
+
const text = escapes ? expandEscapes(expanded) : expanded;
|
|
23
52
|
|
|
24
53
|
return {
|
|
25
|
-
stdout:
|
|
54
|
+
stdout: noNewline ? text : `${text}\n`,
|
|
26
55
|
exitCode: 0,
|
|
27
56
|
};
|
|
28
57
|
},
|
package/src/commands/env.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/** biome-ignore-all lint/style/useNamingConvention: ENV VARS */
|
|
2
2
|
import type { ShellModule } from "../types/commands";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Print environment variables for the current session.
|
|
6
|
+
* @category shell
|
|
7
|
+
* @params []
|
|
8
|
+
*/
|
|
4
9
|
export const envCommand: ShellModule = {
|
|
5
10
|
name: "env",
|
|
6
11
|
description: "Print environment variables",
|
|
@@ -8,6 +13,11 @@ export const envCommand: ShellModule = {
|
|
|
8
13
|
params: [],
|
|
9
14
|
run: ({ env, authUser }) => {
|
|
10
15
|
const vars = { ...env.vars, USER: authUser, HOME: `/home/${authUser}` };
|
|
11
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
stdout: Object.entries(vars)
|
|
18
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
19
|
+
.join("\n"),
|
|
20
|
+
exitCode: 0,
|
|
21
|
+
};
|
|
12
22
|
},
|
|
13
23
|
};
|
package/src/commands/exit.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Exit the current shell session (closeSession flag).
|
|
5
|
+
* @category shell
|
|
6
|
+
* @params ["[code]"]
|
|
7
|
+
*/
|
|
3
8
|
export const exitCommand: ShellModule = {
|
|
4
9
|
name: "exit",
|
|
5
10
|
aliases: ["bye"],
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
description: "Exit the shell session",
|
|
12
|
+
category: "shell",
|
|
13
|
+
params: ["[code]"],
|
|
14
|
+
run: ({ args }) => ({
|
|
15
|
+
closeSession: true,
|
|
16
|
+
exitCode: parseInt(args[0] ?? "0", 10) || 0,
|
|
17
|
+
}),
|
|
8
18
|
};
|
package/src/commands/export.ts
CHANGED
|
@@ -7,7 +7,9 @@ export const exportCommand: ShellModule = {
|
|
|
7
7
|
params: ["[VAR=value]"],
|
|
8
8
|
run: ({ args, env }) => {
|
|
9
9
|
if (args.length === 0) {
|
|
10
|
-
const out = Object.entries(env.vars)
|
|
10
|
+
const out = Object.entries(env.vars)
|
|
11
|
+
.map(([k, v]) => `declare -x ${k}="${v}"`)
|
|
12
|
+
.join("\n");
|
|
11
13
|
return { stdout: out, exitCode: 0 };
|
|
12
14
|
}
|
|
13
15
|
for (const arg of args) {
|
package/src/commands/find.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { ShellModule } from "../types/commands";
|
|
|
2
2
|
import { getFlag } from "./command-helpers";
|
|
3
3
|
import { assertPathAccess, resolvePath } from "./helpers";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Find files and directories by name and type with minimal pattern support.
|
|
7
|
+
* @category files
|
|
8
|
+
* @params ["[path] [-name <pattern>] [-type f|d]"]
|
|
9
|
+
*/
|
|
5
10
|
export const findCommand: ShellModule = {
|
|
6
11
|
name: "find",
|
|
7
12
|
description: "Search for files",
|