@lifo-sh/core 0.5.0 → 0.5.6
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/dist/args-BhoL0JcG.js +58 -0
- package/dist/awk-DahiO6Jl.js +170 -0
- package/dist/base64-Dj_AnQAH.js +92 -0
- package/dist/basename-D8sjWfzX.js +14 -0
- package/dist/bc-CCuJi0IY.js +230 -0
- package/dist/browser-B0dadKCA.js +43 -0
- package/dist/cal-DQsLvArw.js +85 -0
- package/dist/cat-KYGveROo.js +32 -0
- package/dist/chmod-gYZdg3Kv.js +81 -0
- package/dist/chown-DoPi7NLO.js +32 -0
- package/dist/commands/net/curl.d.ts +2 -2
- package/dist/commands/net/curl.d.ts.map +1 -1
- package/dist/commands/net/forward.d.ts +14 -0
- package/dist/commands/net/forward.d.ts.map +1 -0
- package/dist/commands/net/host.d.ts +14 -0
- package/dist/commands/net/host.d.ts.map +1 -0
- package/dist/commands/net/ifconfig.d.ts +8 -0
- package/dist/commands/net/ifconfig.d.ts.map +1 -0
- package/dist/commands/net/ip.d.ts +14 -0
- package/dist/commands/net/ip.d.ts.map +1 -0
- package/dist/commands/net/netstat.d.ts +8 -0
- package/dist/commands/net/netstat.d.ts.map +1 -0
- package/dist/commands/net/ports.d.ts +8 -0
- package/dist/commands/net/ports.d.ts.map +1 -0
- package/dist/commands/net/route.d.ts +8 -0
- package/dist/commands/net/route.d.ts.map +1 -0
- package/dist/commands/net/test-registry.d.ts +8 -0
- package/dist/commands/net/test-registry.d.ts.map +1 -0
- package/dist/commands/net/tunnel-v2.d.ts +4 -0
- package/dist/commands/net/tunnel-v2.d.ts.map +1 -0
- package/dist/commands/net/tunnel.d.ts +6 -0
- package/dist/commands/net/tunnel.d.ts.map +1 -0
- package/dist/commands/registry.d.ts +1 -0
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/system/kill.d.ts +2 -2
- package/dist/commands/system/kill.d.ts.map +1 -1
- package/dist/commands/system/lifo.d.ts +19 -2
- package/dist/commands/system/lifo.d.ts.map +1 -1
- package/dist/commands/system/newtab.d.ts +8 -0
- package/dist/commands/system/newtab.d.ts.map +1 -0
- package/dist/commands/system/node.d.ts +3 -2
- package/dist/commands/system/node.d.ts.map +1 -1
- package/dist/commands/system/npm.d.ts +20 -7
- package/dist/commands/system/npm.d.ts.map +1 -1
- package/dist/commands/system/ps.d.ts +3 -2
- package/dist/commands/system/ps.d.ts.map +1 -1
- package/dist/commands/system/systemctl.d.ts +4 -0
- package/dist/commands/system/systemctl.d.ts.map +1 -0
- package/dist/commands/system/top.d.ts +2 -2
- package/dist/commands/system/top.d.ts.map +1 -1
- package/dist/commands/system/watch.d.ts.map +1 -1
- package/dist/commands/system/whoami.d.ts.map +1 -1
- package/dist/commands/types.d.ts +3 -2
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/cp-BP7-nkZi.js +29 -0
- package/dist/cut-Dg3Sxlw_.js +84 -0
- package/dist/date-DqL4oCg8.js +91 -0
- package/dist/df-CEHqyq91.js +47 -0
- package/dist/diff-aYLFp43G.js +250 -0
- package/dist/dig-0_V5UoWW.js +91 -0
- package/dist/dirname-ByojkmnI.js +14 -0
- package/dist/du-feoEC53Q.js +89 -0
- package/dist/env-CIcDulqw.js +10 -0
- package/dist/fastfetch-CRfsfb4t.js +378 -0
- package/dist/file-BHHCgjt9.js +79 -0
- package/dist/find-C-pGJyTZ.js +63 -0
- package/dist/free-DCkGta9v.js +33 -0
- package/dist/grep-Bv7fu1qw.js +179 -0
- package/dist/gunzip-BZk2000a.js +57 -0
- package/dist/gzip-D55LwDu8.js +70 -0
- package/dist/head-CQQ8pAha.js +66 -0
- package/dist/hostname-Ba0tnCzG.js +8 -0
- package/dist/index-GLjTMF7C.js +22717 -0
- package/dist/index.d.ts +44 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +99 -72
- package/dist/less-C-8XcQ_A.js +294 -0
- package/dist/ln-CpXREm6e.js +15 -0
- package/dist/ls-Ce1mcASB.js +132 -0
- package/dist/{man-Dg26tZ-a.js → man-DjxHeM01.js} +46 -27
- package/dist/mime-B5knsVEw.js +101 -0
- package/dist/mkdir-CtDdaiaM.js +31 -0
- package/dist/mktemp-DwAY8Lz2.js +44 -0
- package/dist/mv-vS020rcy.js +29 -0
- package/dist/nano-DKfqXthq.js +445 -0
- package/dist/nl-DHh-MmKX.js +66 -0
- package/dist/ping-BQO3Z9CT.js +72 -0
- package/dist/pkg/PackageManager.d.ts +2 -2
- package/dist/pkg/PackageManager.d.ts.map +1 -1
- package/dist/pkg/lifo-dev.d.ts +6 -6
- package/dist/pkg/lifo-dev.d.ts.map +1 -1
- package/dist/pkg/lifo-runtime.d.ts +3 -3
- package/dist/pkg/lifo-runtime.d.ts.map +1 -1
- package/dist/pkg/loader.d.ts +2 -2
- package/dist/pkg/loader.d.ts.map +1 -1
- package/dist/printf-CdBVx2dT.js +81 -0
- package/dist/realpath-CZ_ja3FL.js +27 -0
- package/dist/rev-KZ9O5vNS.js +42 -0
- package/dist/rm-dW7YB25j.js +48 -0
- package/dist/rmdir-Db2wctQ6.js +42 -0
- package/dist/runtime/ContextSerialization.d.ts +7 -0
- package/dist/runtime/ContextSerialization.d.ts.map +1 -0
- package/dist/runtime/ProcessExecutor.d.ts +14 -0
- package/dist/runtime/ProcessExecutor.d.ts.map +1 -0
- package/dist/runtime/command-worker.d.ts +9 -0
- package/dist/runtime/command-worker.d.ts.map +1 -0
- package/dist/sandbox/Sandbox.d.ts +1 -2
- package/dist/sandbox/Sandbox.d.ts.map +1 -1
- package/dist/sandbox/SandboxFs.d.ts +2 -2
- package/dist/sandbox/SandboxFs.d.ts.map +1 -1
- package/dist/sandbox/types.d.ts +1 -2
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sed-BK_pjM2M.js +142 -0
- package/dist/seq-B0yurkx9.js +64 -0
- package/dist/sha256sum-BP0l9D35.js +85 -0
- package/dist/shell/ProcessRegistry.d.ts +152 -0
- package/dist/shell/ProcessRegistry.d.ts.map +1 -0
- package/dist/shell/ProcessRegistry.example.d.ts +8 -0
- package/dist/shell/ProcessRegistry.example.d.ts.map +1 -0
- package/dist/shell/ProcessRegistry.test.d.ts +2 -0
- package/dist/shell/ProcessRegistry.test.d.ts.map +1 -0
- package/dist/shell/Shell.d.ts +13 -4
- package/dist/shell/Shell.d.ts.map +1 -1
- package/dist/shell/completer.d.ts +2 -2
- package/dist/shell/completer.d.ts.map +1 -1
- package/dist/shell/expander.d.ts +2 -2
- package/dist/shell/expander.d.ts.map +1 -1
- package/dist/shell/history.d.ts +2 -2
- package/dist/shell/history.d.ts.map +1 -1
- package/dist/shell/interpreter.d.ts +8 -2
- package/dist/shell/interpreter.d.ts.map +1 -1
- package/dist/shell/test-builtin.d.ts +2 -2
- package/dist/shell/test-builtin.d.ts.map +1 -1
- package/dist/sl-BmMNz7ir.js +200 -0
- package/dist/sleep-C_3mjcFi.js +25 -0
- package/dist/sort-DYZuiMaO.js +87 -0
- package/dist/stat-CXSSmsrA.js +38 -0
- package/dist/strings-BwqQy-zL.js +63 -0
- package/dist/tac-CuZSbu_c.js +32 -0
- package/dist/tail-DH7xR0rW.js +62 -0
- package/dist/tar-AnR03GXP.js +155 -0
- package/dist/tee-ByHsMExU.js +29 -0
- package/dist/touch-CcmnMpg5.js +26 -0
- package/dist/tr-D_cg13q8.js +92 -0
- package/dist/tree-Ck1ymlSv.js +64 -0
- package/dist/uname-07bQ7DTD.js +50 -0
- package/dist/uniq-BHkwpex3.js +76 -0
- package/dist/unzip-DVjk3GA4.js +91 -0
- package/dist/uptime-ujk4Nb77.js +17 -0
- package/dist/utils/archive.d.ts +2 -2
- package/dist/utils/archive.d.ts.map +1 -1
- package/dist/utils/glob.d.ts +2 -2
- package/dist/utils/glob.d.ts.map +1 -1
- package/dist/wc-CK9Flybx.js +98 -0
- package/dist/wget-Cww1uNE2.js +84 -0
- package/dist/{which-D3u0cwyh.js → which-CJwCjtVK.js} +25 -14
- package/dist/whoami-EHyrQ1q-.js +25 -0
- package/dist/xargs-I1ZWqhOp.js +40 -0
- package/dist/yes-XolnW6bp.js +11 -0
- package/dist/zip-BTmRwUYQ.js +40 -0
- package/package.json +16 -10
- package/dist/args-CG6b9cZt.js +0 -43
- package/dist/awk-CC_Qo0hQ.js +0 -123
- package/dist/base64-BBckAmkE.js +0 -72
- package/dist/basename-BIICW06y.js +0 -12
- package/dist/bc-BYiKVTNg.js +0 -200
- package/dist/cal-DPULSAhj.js +0 -56
- package/dist/cat-Jv35D4BV.js +0 -29
- package/dist/chmod-Bh-u8XOr.js +0 -56
- package/dist/chown-Dv7xfl2a.js +0 -28
- package/dist/cp-CB-sGTRH.js +0 -19
- package/dist/cut-B79kgCm4.js +0 -65
- package/dist/date-C8NB8v8G.js +0 -86
- package/dist/df-CeZb4WOr.js +0 -34
- package/dist/diff-D5Ej-JEe.js +0 -150
- package/dist/dig-BEJ8Ky96.js +0 -69
- package/dist/dirname-w2Y6csox.js +0 -13
- package/dist/du-UupzdKc_.js +0 -77
- package/dist/env-DXzvDKsN.js +0 -9
- package/dist/fastfetch-aPM9Z3ym.js +0 -310
- package/dist/file-DOl4Wjtc.js +0 -70
- package/dist/find-C0T-P7sl.js +0 -36
- package/dist/free-DAxE4b2U.js +0 -23
- package/dist/grep-Blwrv9k5.js +0 -147
- package/dist/gunzip-R7EtgP15.js +0 -47
- package/dist/gzip-BxF7M1np.js +0 -57
- package/dist/head-CJwcsX18.js +0 -53
- package/dist/hostname-BxU2S3nT.js +0 -8
- package/dist/index-BjKSFBDg.js +0 -8640
- package/dist/kernel/index.d.ts +0 -26
- package/dist/kernel/index.d.ts.map +0 -1
- package/dist/kernel/persistence/PersistenceManager.d.ts +0 -12
- package/dist/kernel/persistence/PersistenceManager.d.ts.map +0 -1
- package/dist/kernel/persistence/backends.d.ts +0 -22
- package/dist/kernel/persistence/backends.d.ts.map +0 -1
- package/dist/kernel/persistence/index.d.ts +0 -6
- package/dist/kernel/persistence/index.d.ts.map +0 -1
- package/dist/kernel/persistence/serializer.d.ts +0 -21
- package/dist/kernel/persistence/serializer.d.ts.map +0 -1
- package/dist/kernel/samples.d.ts +0 -3
- package/dist/kernel/samples.d.ts.map +0 -1
- package/dist/kernel/storage/BlobStore.d.ts +0 -31
- package/dist/kernel/storage/BlobStore.d.ts.map +0 -1
- package/dist/kernel/storage/ContentStore.d.ts +0 -52
- package/dist/kernel/storage/ContentStore.d.ts.map +0 -1
- package/dist/kernel/storage/index.d.ts +0 -7
- package/dist/kernel/storage/index.d.ts.map +0 -1
- package/dist/kernel/vfs/VFS.d.ts +0 -64
- package/dist/kernel/vfs/VFS.d.ts.map +0 -1
- package/dist/kernel/vfs/index.d.ts +0 -7
- package/dist/kernel/vfs/index.d.ts.map +0 -1
- package/dist/kernel/vfs/providers/DevProvider.d.ts +0 -11
- package/dist/kernel/vfs/providers/DevProvider.d.ts.map +0 -1
- package/dist/kernel/vfs/providers/NativeFsProvider.d.ts +0 -63
- package/dist/kernel/vfs/providers/NativeFsProvider.d.ts.map +0 -1
- package/dist/kernel/vfs/providers/ProcProvider.d.ts +0 -14
- package/dist/kernel/vfs/providers/ProcProvider.d.ts.map +0 -1
- package/dist/kernel/vfs/types.d.ts +0 -70
- package/dist/kernel/vfs/types.d.ts.map +0 -1
- package/dist/less-B0gFLJ_7.js +0 -230
- package/dist/ln-Bf3f3jVA.js +0 -11
- package/dist/ls-YnhMRefh.js +0 -106
- package/dist/mkdir-DY1P3Jxj.js +0 -27
- package/dist/mktemp-BRzo2c8y.js +0 -31
- package/dist/mv-bH08L-F_.js +0 -19
- package/dist/nano-CueO2oS0.js +0 -304
- package/dist/nl-D26SSOD4.js +0 -51
- package/dist/node-compat/buffer.d.ts +0 -44
- package/dist/node-compat/buffer.d.ts.map +0 -1
- package/dist/node-compat/child_process.d.ts +0 -10
- package/dist/node-compat/child_process.d.ts.map +0 -1
- package/dist/node-compat/console.d.ts +0 -21
- package/dist/node-compat/console.d.ts.map +0 -1
- package/dist/node-compat/crypto.d.ts +0 -17
- package/dist/node-compat/crypto.d.ts.map +0 -1
- package/dist/node-compat/events.d.ts +0 -19
- package/dist/node-compat/events.d.ts.map +0 -1
- package/dist/node-compat/fs.d.ts +0 -175
- package/dist/node-compat/fs.d.ts.map +0 -1
- package/dist/node-compat/http.d.ts +0 -87
- package/dist/node-compat/http.d.ts.map +0 -1
- package/dist/node-compat/index.d.ts +0 -19
- package/dist/node-compat/index.d.ts.map +0 -1
- package/dist/node-compat/os.d.ts +0 -39
- package/dist/node-compat/os.d.ts.map +0 -1
- package/dist/node-compat/path.d.ts +0 -58
- package/dist/node-compat/path.d.ts.map +0 -1
- package/dist/node-compat/process.d.ts +0 -62
- package/dist/node-compat/process.d.ts.map +0 -1
- package/dist/node-compat/stream.d.ts +0 -36
- package/dist/node-compat/stream.d.ts.map +0 -1
- package/dist/node-compat/string_decoder.d.ts +0 -11
- package/dist/node-compat/string_decoder.d.ts.map +0 -1
- package/dist/node-compat/timers.d.ts +0 -16
- package/dist/node-compat/timers.d.ts.map +0 -1
- package/dist/node-compat/url.d.ts +0 -53
- package/dist/node-compat/url.d.ts.map +0 -1
- package/dist/node-compat/util.d.ts +0 -27
- package/dist/node-compat/util.d.ts.map +0 -1
- package/dist/node-compat/zlib.d.ts +0 -66
- package/dist/node-compat/zlib.d.ts.map +0 -1
- package/dist/ping-DtVEwwda.js +0 -50
- package/dist/printf-Cc2o7KZx.js +0 -70
- package/dist/realpath-BH29Lem_.js +0 -24
- package/dist/rev-ySwmRf_K.js +0 -39
- package/dist/rm-D7iWUUE2.js +0 -37
- package/dist/rmdir-BLtdNjt1.js +0 -35
- package/dist/sed-DwBPYYFb.js +0 -95
- package/dist/seq-B01YKIbO.js +0 -37
- package/dist/sha256sum-DED6ePiU.js +0 -64
- package/dist/sl-Dv4iPBN6.js +0 -138
- package/dist/sleep-B4C3fZiR.js +0 -19
- package/dist/sort-OXqZY83v.js +0 -64
- package/dist/stat-BvwNpE5B.js +0 -29
- package/dist/strings-BesRwUt_.js +0 -42
- package/dist/tac-D4BMSdj9.js +0 -31
- package/dist/tail-xVmLkzJK.js +0 -52
- package/dist/tar-BHRJ0-4j.js +0 -120
- package/dist/tee-DxygINEJ.js +0 -17
- package/dist/touch-DCb9Qn5q.js +0 -23
- package/dist/tr-DsCiwSIu.js +0 -60
- package/dist/tree-4QpgsnA0.js +0 -46
- package/dist/uname-BCn8HlJD.js +0 -37
- package/dist/uniq-xmgE0zRj.js +0 -54
- package/dist/unzip-CDKcoB0B.js +0 -81
- package/dist/uptime-CgBJegqU.js +0 -8
- package/dist/wc-B-jNRfLa.js +0 -69
- package/dist/wget-CO-45JoL.js +0 -53
- package/dist/whoami-Y18wqme3.js +0 -25
- package/dist/xargs-DfbCRFFd.js +0 -35
- package/dist/yes-DXEyHHD2.js +0 -10
- package/dist/zip-Cu1DzbAu.js +0 -33
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
import { i as isBinaryMime, g as getMimeType } from "./mime-B5knsVEw.js";
|
|
3
|
+
const command = async (ctx) => {
|
|
4
|
+
let reverse = false;
|
|
5
|
+
let numeric = false;
|
|
6
|
+
let unique = false;
|
|
7
|
+
let keyField = 0;
|
|
8
|
+
const files = [];
|
|
9
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
10
|
+
const arg = ctx.args[i];
|
|
11
|
+
if (arg === "-k" && i + 1 < ctx.args.length) {
|
|
12
|
+
keyField = parseInt(ctx.args[++i], 10);
|
|
13
|
+
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
14
|
+
for (let j = 1; j < arg.length; j++) {
|
|
15
|
+
switch (arg[j]) {
|
|
16
|
+
case "r":
|
|
17
|
+
reverse = true;
|
|
18
|
+
break;
|
|
19
|
+
case "n":
|
|
20
|
+
numeric = true;
|
|
21
|
+
break;
|
|
22
|
+
case "u":
|
|
23
|
+
unique = true;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
files.push(arg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let text = "";
|
|
32
|
+
if (files.length === 0) {
|
|
33
|
+
if (ctx.stdin) {
|
|
34
|
+
text = await ctx.stdin.readAll();
|
|
35
|
+
} else {
|
|
36
|
+
ctx.stderr.write("sort: missing file operand\n");
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
const path = resolve(ctx.cwd, file);
|
|
42
|
+
try {
|
|
43
|
+
ctx.vfs.stat(path);
|
|
44
|
+
if (isBinaryMime(getMimeType(path))) {
|
|
45
|
+
ctx.stderr.write(`sort: ${file}: binary file, skipping
|
|
46
|
+
`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
text += ctx.vfs.readFileString(path);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof VFSError) {
|
|
52
|
+
ctx.stderr.write(`sort: ${file}: ${e.message}
|
|
53
|
+
`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let lines = text.replace(/\n$/, "").split("\n");
|
|
61
|
+
function getKey(line) {
|
|
62
|
+
if (keyField > 0) {
|
|
63
|
+
const fields = line.split(/\s+/);
|
|
64
|
+
return fields[keyField - 1] || "";
|
|
65
|
+
}
|
|
66
|
+
return line;
|
|
67
|
+
}
|
|
68
|
+
lines.sort((a, b) => {
|
|
69
|
+
const ka = getKey(a);
|
|
70
|
+
const kb = getKey(b);
|
|
71
|
+
let cmp;
|
|
72
|
+
if (numeric) {
|
|
73
|
+
cmp = (parseFloat(ka) || 0) - (parseFloat(kb) || 0);
|
|
74
|
+
} else {
|
|
75
|
+
cmp = ka.localeCompare(kb);
|
|
76
|
+
}
|
|
77
|
+
return reverse ? -cmp : cmp;
|
|
78
|
+
});
|
|
79
|
+
if (unique) {
|
|
80
|
+
lines = lines.filter((line, idx) => idx === 0 || line !== lines[idx - 1]);
|
|
81
|
+
}
|
|
82
|
+
ctx.stdout.write(lines.join("\n") + "\n");
|
|
83
|
+
return 0;
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
command as default
|
|
87
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
if (ctx.args.length === 0) {
|
|
4
|
+
ctx.stderr.write("stat: missing operand\n");
|
|
5
|
+
return 1;
|
|
6
|
+
}
|
|
7
|
+
let exitCode = 0;
|
|
8
|
+
for (const arg of ctx.args) {
|
|
9
|
+
const path = resolve(ctx.cwd, arg);
|
|
10
|
+
try {
|
|
11
|
+
const st = ctx.vfs.stat(path);
|
|
12
|
+
const mode = "0" + st.mode.toString(8);
|
|
13
|
+
const type = st.type === "directory" ? "directory" : "regular file";
|
|
14
|
+
ctx.stdout.write(` File: ${arg}
|
|
15
|
+
`);
|
|
16
|
+
ctx.stdout.write(` Size: ${st.size} Type: ${type}
|
|
17
|
+
`);
|
|
18
|
+
ctx.stdout.write(` Mode: ${mode}
|
|
19
|
+
`);
|
|
20
|
+
ctx.stdout.write(` Created: ${new Date(st.ctime).toISOString()}
|
|
21
|
+
`);
|
|
22
|
+
ctx.stdout.write(` Modified: ${new Date(st.mtime).toISOString()}
|
|
23
|
+
`);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (e instanceof VFSError) {
|
|
26
|
+
ctx.stderr.write(`stat: ${arg}: ${e.message}
|
|
27
|
+
`);
|
|
28
|
+
exitCode = 1;
|
|
29
|
+
} else {
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return exitCode;
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
command as default
|
|
38
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
function extractStrings(data, minLen) {
|
|
3
|
+
const results = [];
|
|
4
|
+
let current = "";
|
|
5
|
+
for (let i = 0; i < data.length; i++) {
|
|
6
|
+
const byte = data[i];
|
|
7
|
+
if (byte >= 32 && byte <= 126 || byte === 9) {
|
|
8
|
+
current += String.fromCharCode(byte);
|
|
9
|
+
} else {
|
|
10
|
+
if (current.length >= minLen) {
|
|
11
|
+
results.push(current);
|
|
12
|
+
}
|
|
13
|
+
current = "";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (current.length >= minLen) {
|
|
17
|
+
results.push(current);
|
|
18
|
+
}
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
const command = async (ctx) => {
|
|
22
|
+
let minLen = 4;
|
|
23
|
+
const files = [];
|
|
24
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
25
|
+
const arg = ctx.args[i];
|
|
26
|
+
if (arg === "-n" && i + 1 < ctx.args.length) {
|
|
27
|
+
minLen = parseInt(ctx.args[++i], 10);
|
|
28
|
+
if (isNaN(minLen) || minLen < 1) minLen = 4;
|
|
29
|
+
} else if (arg.startsWith("-") && arg.length > 1 && !isNaN(parseInt(arg.slice(1), 10))) {
|
|
30
|
+
minLen = parseInt(arg.slice(1), 10);
|
|
31
|
+
if (minLen < 1) minLen = 4;
|
|
32
|
+
} else {
|
|
33
|
+
files.push(arg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let exitCode = 0;
|
|
37
|
+
if (files.length === 0) {
|
|
38
|
+
ctx.stderr.write("Usage: strings [-n MIN] FILE...\n");
|
|
39
|
+
ctx.stderr.write("Print sequences of printable characters from files.\n");
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const path = resolve(ctx.cwd, file);
|
|
44
|
+
try {
|
|
45
|
+
const data = ctx.vfs.readFile(path);
|
|
46
|
+
for (const s of extractStrings(data, minLen)) {
|
|
47
|
+
ctx.stdout.write(s + "\n");
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof VFSError) {
|
|
51
|
+
ctx.stderr.write(`strings: ${file}: ${e.message}
|
|
52
|
+
`);
|
|
53
|
+
exitCode = 1;
|
|
54
|
+
} else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return exitCode;
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
command as default
|
|
63
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
let exitCode = 0;
|
|
4
|
+
const processContent = (content) => {
|
|
5
|
+
const lines = content.replace(/\n$/, "").split("\n");
|
|
6
|
+
lines.reverse();
|
|
7
|
+
ctx.stdout.write(lines.join("\n") + "\n");
|
|
8
|
+
};
|
|
9
|
+
if (ctx.args.length === 0) {
|
|
10
|
+
ctx.stderr.write("Usage: tac FILE...\n");
|
|
11
|
+
ctx.stderr.write("Print files in reverse line order.\n");
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
for (const arg of ctx.args) {
|
|
15
|
+
const path = resolve(ctx.cwd, arg);
|
|
16
|
+
try {
|
|
17
|
+
processContent(ctx.vfs.readFileString(path));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e instanceof VFSError) {
|
|
20
|
+
ctx.stderr.write(`tac: ${arg}: ${e.message}
|
|
21
|
+
`);
|
|
22
|
+
exitCode = 1;
|
|
23
|
+
} else {
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return exitCode;
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
command as default
|
|
32
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
import { i as isBinaryMime, g as getMimeType } from "./mime-B5knsVEw.js";
|
|
3
|
+
const command = async (ctx) => {
|
|
4
|
+
let count = 10;
|
|
5
|
+
const files = [];
|
|
6
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
7
|
+
const arg = ctx.args[i];
|
|
8
|
+
if (arg === "-n" && i + 1 < ctx.args.length) {
|
|
9
|
+
count = parseInt(ctx.args[++i], 10);
|
|
10
|
+
if (isNaN(count)) {
|
|
11
|
+
ctx.stderr.write("tail: invalid number of lines\n");
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
} else if (/^-\d+$/.test(arg)) {
|
|
15
|
+
count = parseInt(arg.slice(1), 10);
|
|
16
|
+
} else {
|
|
17
|
+
files.push(arg);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function tailText(text) {
|
|
21
|
+
const lines = text.replace(/\n$/, "").split("\n");
|
|
22
|
+
const selected = lines.slice(-count);
|
|
23
|
+
ctx.stdout.write(selected.join("\n") + "\n");
|
|
24
|
+
}
|
|
25
|
+
if (files.length === 0) {
|
|
26
|
+
if (ctx.stdin) {
|
|
27
|
+
await tailText(await ctx.stdin.readAll());
|
|
28
|
+
} else {
|
|
29
|
+
ctx.stderr.write("tail: missing file operand\n");
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
let exitCode = 0;
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
const path = resolve(ctx.cwd, file);
|
|
37
|
+
try {
|
|
38
|
+
ctx.vfs.stat(path);
|
|
39
|
+
if (isBinaryMime(getMimeType(path))) {
|
|
40
|
+
ctx.stderr.write(`tail: ${file}: binary file, skipping
|
|
41
|
+
`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const content = ctx.vfs.readFileString(path);
|
|
45
|
+
if (files.length > 1) ctx.stdout.write(`==> ${file} <==
|
|
46
|
+
`);
|
|
47
|
+
await tailText(content);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (e instanceof VFSError) {
|
|
50
|
+
ctx.stderr.write(`tail: ${file}: ${e.message}
|
|
51
|
+
`);
|
|
52
|
+
exitCode = 1;
|
|
53
|
+
} else {
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return exitCode;
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
command as default
|
|
62
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { r as resolve, c as collectFiles, d as createTar, f as compressGzip, h as decompressGzip, p as parseTar, i as dirname, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
let create = false;
|
|
4
|
+
let extract = false;
|
|
5
|
+
let list = false;
|
|
6
|
+
let gzipFlag = false;
|
|
7
|
+
let verbose = false;
|
|
8
|
+
let archiveFile = "";
|
|
9
|
+
let changeDir = "";
|
|
10
|
+
const files = [];
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (i < ctx.args.length) {
|
|
13
|
+
const arg = ctx.args[i];
|
|
14
|
+
if (arg === "--help") {
|
|
15
|
+
ctx.stdout.write("Usage: tar [-c|-x|-t] [-z] [-v] [-f file] [-C dir] [files...]\n");
|
|
16
|
+
ctx.stdout.write(" -c create archive\n");
|
|
17
|
+
ctx.stdout.write(" -x extract archive\n");
|
|
18
|
+
ctx.stdout.write(" -t list archive contents\n");
|
|
19
|
+
ctx.stdout.write(" -z gzip compression\n");
|
|
20
|
+
ctx.stdout.write(" -v verbose\n");
|
|
21
|
+
ctx.stdout.write(" -f archive file\n");
|
|
22
|
+
ctx.stdout.write(" -C change directory\n");
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
if (arg.startsWith("-") && arg !== "-") {
|
|
26
|
+
const chars = arg.slice(1);
|
|
27
|
+
for (let j = 0; j < chars.length; j++) {
|
|
28
|
+
switch (chars[j]) {
|
|
29
|
+
case "c":
|
|
30
|
+
create = true;
|
|
31
|
+
break;
|
|
32
|
+
case "x":
|
|
33
|
+
extract = true;
|
|
34
|
+
break;
|
|
35
|
+
case "t":
|
|
36
|
+
list = true;
|
|
37
|
+
break;
|
|
38
|
+
case "z":
|
|
39
|
+
gzipFlag = true;
|
|
40
|
+
break;
|
|
41
|
+
case "v":
|
|
42
|
+
verbose = true;
|
|
43
|
+
break;
|
|
44
|
+
case "f": {
|
|
45
|
+
const rest = chars.slice(j + 1);
|
|
46
|
+
archiveFile = rest || ctx.args[++i] || "";
|
|
47
|
+
j = chars.length;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "C": {
|
|
51
|
+
const rest = chars.slice(j + 1);
|
|
52
|
+
changeDir = rest || ctx.args[++i] || "";
|
|
53
|
+
j = chars.length;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
default:
|
|
57
|
+
ctx.stderr.write(`tar: unknown option: -${chars[j]}
|
|
58
|
+
`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
files.push(arg);
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
const modeCount = [create, extract, list].filter(Boolean).length;
|
|
68
|
+
if (modeCount === 0) {
|
|
69
|
+
ctx.stderr.write("tar: must specify one of -c, -x, -t\n");
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
if (modeCount > 1) {
|
|
73
|
+
ctx.stderr.write("tar: conflicting options\n");
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (!archiveFile) {
|
|
77
|
+
ctx.stderr.write("tar: -f is required\n");
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
const archivePath = resolve(ctx.cwd, archiveFile);
|
|
81
|
+
const targetDir = changeDir ? resolve(ctx.cwd, changeDir) : ctx.cwd;
|
|
82
|
+
try {
|
|
83
|
+
if (create) {
|
|
84
|
+
if (files.length === 0) {
|
|
85
|
+
ctx.stderr.write("tar: no files to archive\n");
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
const entries = collectFiles(ctx.vfs, targetDir, files);
|
|
89
|
+
let data = createTar(entries);
|
|
90
|
+
if (gzipFlag) {
|
|
91
|
+
data = await compressGzip(data);
|
|
92
|
+
}
|
|
93
|
+
ctx.vfs.writeFile(archivePath, data);
|
|
94
|
+
if (verbose) {
|
|
95
|
+
for (const entry of entries) {
|
|
96
|
+
ctx.stdout.write(`${entry.path}
|
|
97
|
+
`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else if (extract) {
|
|
101
|
+
let data = ctx.vfs.readFile(archivePath);
|
|
102
|
+
if (gzipFlag) {
|
|
103
|
+
data = await decompressGzip(data);
|
|
104
|
+
}
|
|
105
|
+
const entries = parseTar(data);
|
|
106
|
+
if (changeDir) {
|
|
107
|
+
try {
|
|
108
|
+
ctx.vfs.mkdir(targetDir, { recursive: true });
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const entry of entries) {
|
|
113
|
+
const entryPath = resolve(targetDir, entry.path);
|
|
114
|
+
if (entry.type === "directory") {
|
|
115
|
+
try {
|
|
116
|
+
ctx.vfs.mkdir(entryPath, { recursive: true });
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
const parent = dirname(entryPath);
|
|
121
|
+
try {
|
|
122
|
+
ctx.vfs.mkdir(parent, { recursive: true });
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
ctx.vfs.writeFile(entryPath, entry.data);
|
|
126
|
+
}
|
|
127
|
+
if (verbose) {
|
|
128
|
+
ctx.stdout.write(`${entry.path}
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else if (list) {
|
|
133
|
+
let data = ctx.vfs.readFile(archivePath);
|
|
134
|
+
if (gzipFlag) {
|
|
135
|
+
data = await decompressGzip(data);
|
|
136
|
+
}
|
|
137
|
+
const entries = parseTar(data);
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
ctx.stdout.write(`${entry.path}${entry.type === "directory" ? "/" : ""}
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
if (e instanceof VFSError) {
|
|
145
|
+
ctx.stderr.write(`tar: ${e.message}
|
|
146
|
+
`);
|
|
147
|
+
return 2;
|
|
148
|
+
}
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
return 0;
|
|
152
|
+
};
|
|
153
|
+
export {
|
|
154
|
+
command as default
|
|
155
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { r as resolve } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
let append = false;
|
|
4
|
+
const files = [];
|
|
5
|
+
for (const arg of ctx.args) {
|
|
6
|
+
if (arg === "-a") {
|
|
7
|
+
append = true;
|
|
8
|
+
} else {
|
|
9
|
+
files.push(arg);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
let text = "";
|
|
13
|
+
if (ctx.stdin) {
|
|
14
|
+
text = await ctx.stdin.readAll();
|
|
15
|
+
}
|
|
16
|
+
ctx.stdout.write(text);
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const path = resolve(ctx.cwd, file);
|
|
19
|
+
if (append) {
|
|
20
|
+
ctx.vfs.appendFile(path, text);
|
|
21
|
+
} else {
|
|
22
|
+
ctx.vfs.writeFile(path, text);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
command as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
if (ctx.args.length === 0) {
|
|
4
|
+
ctx.stderr.write("touch: missing operand\n");
|
|
5
|
+
return 1;
|
|
6
|
+
}
|
|
7
|
+
let exitCode = 0;
|
|
8
|
+
for (const arg of ctx.args) {
|
|
9
|
+
const path = resolve(ctx.cwd, arg);
|
|
10
|
+
try {
|
|
11
|
+
ctx.vfs.touch(path);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof VFSError) {
|
|
14
|
+
ctx.stderr.write(`touch: ${arg}: ${e.message}
|
|
15
|
+
`);
|
|
16
|
+
exitCode = 1;
|
|
17
|
+
} else {
|
|
18
|
+
throw e;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return exitCode;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
command as default
|
|
26
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
function expandRange(set) {
|
|
2
|
+
let result = "";
|
|
3
|
+
let i = 0;
|
|
4
|
+
while (i < set.length) {
|
|
5
|
+
if (i + 2 < set.length && set[i + 1] === "-") {
|
|
6
|
+
const start = set.charCodeAt(i);
|
|
7
|
+
const end = set.charCodeAt(i + 2);
|
|
8
|
+
for (let c = start; c <= end; c++) {
|
|
9
|
+
result += String.fromCharCode(c);
|
|
10
|
+
}
|
|
11
|
+
i += 3;
|
|
12
|
+
} else {
|
|
13
|
+
result += set[i];
|
|
14
|
+
i++;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
const command = async (ctx) => {
|
|
20
|
+
let deleteMode = false;
|
|
21
|
+
let squeezeMode = false;
|
|
22
|
+
const sets = [];
|
|
23
|
+
for (const arg of ctx.args) {
|
|
24
|
+
if (arg === "-d") {
|
|
25
|
+
deleteMode = true;
|
|
26
|
+
} else if (arg === "-s") {
|
|
27
|
+
squeezeMode = true;
|
|
28
|
+
} else {
|
|
29
|
+
sets.push(arg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (sets.length === 0) {
|
|
33
|
+
ctx.stderr.write("tr: missing operand\n");
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
let text = "";
|
|
37
|
+
if (ctx.stdin) {
|
|
38
|
+
text = await ctx.stdin.readAll();
|
|
39
|
+
} else {
|
|
40
|
+
ctx.stderr.write("tr: missing input\n");
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
const set1 = expandRange(sets[0]);
|
|
44
|
+
if (deleteMode) {
|
|
45
|
+
let result2 = "";
|
|
46
|
+
for (const ch of text) {
|
|
47
|
+
if (!set1.includes(ch)) result2 += ch;
|
|
48
|
+
}
|
|
49
|
+
ctx.stdout.write(result2);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
if (squeezeMode && sets.length === 1) {
|
|
53
|
+
let result2 = "";
|
|
54
|
+
let lastCh = "";
|
|
55
|
+
for (const ch of text) {
|
|
56
|
+
if (set1.includes(ch) && ch === lastCh) continue;
|
|
57
|
+
result2 += ch;
|
|
58
|
+
lastCh = ch;
|
|
59
|
+
}
|
|
60
|
+
ctx.stdout.write(result2);
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
if (sets.length < 2) {
|
|
64
|
+
ctx.stderr.write("tr: missing operand after set1\n");
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
const set2 = expandRange(sets[1]);
|
|
68
|
+
const map = /* @__PURE__ */ new Map();
|
|
69
|
+
for (let i = 0; i < set1.length; i++) {
|
|
70
|
+
map.set(set1[i], set2[Math.min(i, set2.length - 1)]);
|
|
71
|
+
}
|
|
72
|
+
let result = "";
|
|
73
|
+
for (const ch of text) {
|
|
74
|
+
result += map.get(ch) ?? ch;
|
|
75
|
+
}
|
|
76
|
+
if (squeezeMode) {
|
|
77
|
+
const set2Chars = new Set(set2);
|
|
78
|
+
let squeezed = "";
|
|
79
|
+
let lastCh = "";
|
|
80
|
+
for (const ch of result) {
|
|
81
|
+
if (set2Chars.has(ch) && ch === lastCh) continue;
|
|
82
|
+
squeezed += ch;
|
|
83
|
+
lastCh = ch;
|
|
84
|
+
}
|
|
85
|
+
result = squeezed;
|
|
86
|
+
}
|
|
87
|
+
ctx.stdout.write(result);
|
|
88
|
+
return 0;
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
command as default
|
|
92
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { r as resolve, V as VFSError } from "./index-GLjTMF7C.js";
|
|
2
|
+
const command = async (ctx) => {
|
|
3
|
+
let maxDepth = Infinity;
|
|
4
|
+
let dirsOnly = false;
|
|
5
|
+
let targetPath = ".";
|
|
6
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
7
|
+
const arg = ctx.args[i];
|
|
8
|
+
if (arg === "-L" && i + 1 < ctx.args.length) {
|
|
9
|
+
maxDepth = parseInt(ctx.args[++i], 10);
|
|
10
|
+
} else if (arg === "-d") {
|
|
11
|
+
dirsOnly = true;
|
|
12
|
+
} else if (!arg.startsWith("-")) {
|
|
13
|
+
targetPath = arg;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const absPath = resolve(ctx.cwd, targetPath);
|
|
17
|
+
let dirCount = 0;
|
|
18
|
+
let fileCount = 0;
|
|
19
|
+
function printTree(dirPath, prefix, depth) {
|
|
20
|
+
if (depth > maxDepth) return;
|
|
21
|
+
try {
|
|
22
|
+
const entries = ctx.vfs.readdir(dirPath);
|
|
23
|
+
const filtered = dirsOnly ? entries.filter((e) => e.type === "directory") : entries;
|
|
24
|
+
const sorted = filtered.sort((a, b) => a.name.localeCompare(b.name));
|
|
25
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
26
|
+
const entry = sorted[i];
|
|
27
|
+
const isLast = i === sorted.length - 1;
|
|
28
|
+
const connector = isLast ? "└── " : "├── ";
|
|
29
|
+
ctx.stdout.write(prefix + connector + entry.name + "\n");
|
|
30
|
+
if (entry.type === "directory") {
|
|
31
|
+
dirCount++;
|
|
32
|
+
const newPrefix = prefix + (isLast ? " " : "│ ");
|
|
33
|
+
const fullPath = dirPath === "/" ? "/" + entry.name : dirPath + "/" + entry.name;
|
|
34
|
+
printTree(fullPath, newPrefix, depth + 1);
|
|
35
|
+
} else {
|
|
36
|
+
fileCount++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
ctx.vfs.stat(absPath);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (e instanceof VFSError) {
|
|
46
|
+
ctx.stderr.write(`tree: '${targetPath}': ${e.message}
|
|
47
|
+
`);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
ctx.stdout.write(targetPath + "\n");
|
|
53
|
+
printTree(absPath, "", 1);
|
|
54
|
+
const summary = dirsOnly ? `
|
|
55
|
+
${dirCount} directories
|
|
56
|
+
` : `
|
|
57
|
+
${dirCount} directories, ${fileCount} files
|
|
58
|
+
`;
|
|
59
|
+
ctx.stdout.write(summary);
|
|
60
|
+
return 0;
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
command as default
|
|
64
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const command = async (ctx) => {
|
|
2
|
+
const info = {
|
|
3
|
+
sysname: "Lifo",
|
|
4
|
+
release: "1.0.0",
|
|
5
|
+
machine: "wasm"
|
|
6
|
+
};
|
|
7
|
+
if (ctx.args.length === 0) {
|
|
8
|
+
ctx.stdout.write(info.sysname + "\n");
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
let showAll = false;
|
|
12
|
+
let showSysname = false;
|
|
13
|
+
let showRelease = false;
|
|
14
|
+
let showMachine = false;
|
|
15
|
+
for (const arg of ctx.args) {
|
|
16
|
+
if (arg.startsWith("-")) {
|
|
17
|
+
for (let i = 1; i < arg.length; i++) {
|
|
18
|
+
switch (arg[i]) {
|
|
19
|
+
case "a":
|
|
20
|
+
showAll = true;
|
|
21
|
+
break;
|
|
22
|
+
case "s":
|
|
23
|
+
showSysname = true;
|
|
24
|
+
break;
|
|
25
|
+
case "r":
|
|
26
|
+
showRelease = true;
|
|
27
|
+
break;
|
|
28
|
+
case "m":
|
|
29
|
+
showMachine = true;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (showAll) {
|
|
36
|
+
ctx.stdout.write(`${info.sysname} ${info.release} ${info.machine}
|
|
37
|
+
`);
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
const parts = [];
|
|
41
|
+
if (showSysname) parts.push(info.sysname);
|
|
42
|
+
if (showRelease) parts.push(info.release);
|
|
43
|
+
if (showMachine) parts.push(info.machine);
|
|
44
|
+
if (parts.length === 0) parts.push(info.sysname);
|
|
45
|
+
ctx.stdout.write(parts.join(" ") + "\n");
|
|
46
|
+
return 0;
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
command as default
|
|
50
|
+
};
|