shell-dsl 0.0.9 → 0.0.11
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/cjs/package.json +1 -1
- package/dist/cjs/src/commands/awk/awk.cjs +79 -32
- package/dist/cjs/src/commands/awk/awk.cjs.map +3 -3
- package/dist/cjs/src/commands/cat/cat.cjs +16 -3
- package/dist/cjs/src/commands/cat/cat.cjs.map +3 -3
- package/dist/cjs/src/commands/colon/colon.cjs +39 -0
- package/dist/cjs/src/commands/colon/colon.cjs.map +10 -0
- package/dist/cjs/src/commands/cp/cp.cjs +26 -20
- package/dist/cjs/src/commands/cp/cp.cjs.map +3 -3
- package/dist/cjs/src/commands/echo/echo.cjs +22 -7
- package/dist/cjs/src/commands/echo/echo.cjs.map +3 -3
- package/dist/cjs/src/commands/grep/grep.cjs +166 -139
- package/dist/cjs/src/commands/grep/grep.cjs.map +3 -3
- package/dist/cjs/src/commands/head/head.cjs +29 -14
- package/dist/cjs/src/commands/head/head.cjs.map +3 -3
- package/dist/cjs/src/commands/index.cjs +6 -2
- package/dist/cjs/src/commands/index.cjs.map +3 -3
- package/dist/cjs/src/commands/ls/ls.cjs +27 -27
- package/dist/cjs/src/commands/ls/ls.cjs.map +3 -3
- package/dist/cjs/src/commands/mkdir/mkdir.cjs +21 -10
- package/dist/cjs/src/commands/mkdir/mkdir.cjs.map +3 -3
- package/dist/cjs/src/commands/mv/mv.cjs +22 -15
- package/dist/cjs/src/commands/mv/mv.cjs.map +3 -3
- package/dist/cjs/src/commands/pwd/pwd.cjs +13 -1
- package/dist/cjs/src/commands/pwd/pwd.cjs.map +3 -3
- package/dist/cjs/src/commands/rm/rm.cjs +25 -22
- package/dist/cjs/src/commands/rm/rm.cjs.map +3 -3
- package/dist/cjs/src/commands/sed/sed.cjs +87 -25
- package/dist/cjs/src/commands/sed/sed.cjs.map +3 -3
- package/dist/cjs/src/commands/sort/sort.cjs +27 -24
- package/dist/cjs/src/commands/sort/sort.cjs.map +3 -3
- package/dist/cjs/src/commands/tail/tail.cjs +29 -14
- package/dist/cjs/src/commands/tail/tail.cjs.map +3 -3
- package/dist/cjs/src/commands/tee/tee.cjs +21 -10
- package/dist/cjs/src/commands/tee/tee.cjs.map +3 -3
- package/dist/cjs/src/commands/touch/touch.cjs +21 -10
- package/dist/cjs/src/commands/touch/touch.cjs.map +3 -3
- package/dist/cjs/src/commands/tree/tree.cjs +45 -48
- package/dist/cjs/src/commands/tree/tree.cjs.map +3 -3
- package/dist/cjs/src/commands/uniq/uniq.cjs +27 -24
- package/dist/cjs/src/commands/uniq/uniq.cjs.map +3 -3
- package/dist/cjs/src/commands/wc/wc.cjs +28 -24
- package/dist/cjs/src/commands/wc/wc.cjs.map +3 -3
- package/dist/cjs/src/fs/memfs-adapter.cjs +3 -1
- package/dist/cjs/src/fs/memfs-adapter.cjs.map +3 -3
- package/dist/cjs/src/interpreter/interpreter.cjs +32 -7
- package/dist/cjs/src/interpreter/interpreter.cjs.map +3 -3
- package/dist/cjs/src/parser/parser.cjs +3 -3
- package/dist/cjs/src/parser/parser.cjs.map +3 -3
- package/dist/cjs/src/utils/flag-parser.cjs +162 -0
- package/dist/cjs/src/utils/flag-parser.cjs.map +10 -0
- package/dist/cjs/src/utils/index.cjs +4 -2
- package/dist/cjs/src/utils/index.cjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/commands/awk/awk.mjs +79 -32
- package/dist/mjs/src/commands/awk/awk.mjs.map +3 -3
- package/dist/mjs/src/commands/cat/cat.mjs +16 -3
- package/dist/mjs/src/commands/cat/cat.mjs.map +3 -3
- package/dist/mjs/src/commands/colon/colon.mjs +9 -0
- package/dist/mjs/src/commands/colon/colon.mjs.map +10 -0
- package/dist/mjs/src/commands/cp/cp.mjs +26 -20
- package/dist/mjs/src/commands/cp/cp.mjs.map +3 -3
- package/dist/mjs/src/commands/echo/echo.mjs +22 -7
- package/dist/mjs/src/commands/echo/echo.mjs.map +3 -3
- package/dist/mjs/src/commands/grep/grep.mjs +166 -139
- package/dist/mjs/src/commands/grep/grep.mjs.map +3 -3
- package/dist/mjs/src/commands/head/head.mjs +29 -14
- package/dist/mjs/src/commands/head/head.mjs.map +3 -3
- package/dist/mjs/src/commands/index.mjs +6 -2
- package/dist/mjs/src/commands/index.mjs.map +3 -3
- package/dist/mjs/src/commands/ls/ls.mjs +27 -27
- package/dist/mjs/src/commands/ls/ls.mjs.map +3 -3
- package/dist/mjs/src/commands/mkdir/mkdir.mjs +21 -10
- package/dist/mjs/src/commands/mkdir/mkdir.mjs.map +3 -3
- package/dist/mjs/src/commands/mv/mv.mjs +22 -15
- package/dist/mjs/src/commands/mv/mv.mjs.map +3 -3
- package/dist/mjs/src/commands/pwd/pwd.mjs +13 -1
- package/dist/mjs/src/commands/pwd/pwd.mjs.map +3 -3
- package/dist/mjs/src/commands/rm/rm.mjs +25 -22
- package/dist/mjs/src/commands/rm/rm.mjs.map +3 -3
- package/dist/mjs/src/commands/sed/sed.mjs +87 -25
- package/dist/mjs/src/commands/sed/sed.mjs.map +3 -3
- package/dist/mjs/src/commands/sort/sort.mjs +27 -24
- package/dist/mjs/src/commands/sort/sort.mjs.map +3 -3
- package/dist/mjs/src/commands/tail/tail.mjs +29 -14
- package/dist/mjs/src/commands/tail/tail.mjs.map +3 -3
- package/dist/mjs/src/commands/tee/tee.mjs +21 -10
- package/dist/mjs/src/commands/tee/tee.mjs.map +3 -3
- package/dist/mjs/src/commands/touch/touch.mjs +21 -10
- package/dist/mjs/src/commands/touch/touch.mjs.map +3 -3
- package/dist/mjs/src/commands/tree/tree.mjs +45 -48
- package/dist/mjs/src/commands/tree/tree.mjs.map +3 -3
- package/dist/mjs/src/commands/uniq/uniq.mjs +27 -24
- package/dist/mjs/src/commands/uniq/uniq.mjs.map +3 -3
- package/dist/mjs/src/commands/wc/wc.mjs +28 -24
- package/dist/mjs/src/commands/wc/wc.mjs.map +3 -3
- package/dist/mjs/src/fs/memfs-adapter.mjs +3 -1
- package/dist/mjs/src/fs/memfs-adapter.mjs.map +3 -3
- package/dist/mjs/src/interpreter/interpreter.mjs +32 -7
- package/dist/mjs/src/interpreter/interpreter.mjs.map +3 -3
- package/dist/mjs/src/parser/parser.mjs +3 -3
- package/dist/mjs/src/parser/parser.mjs.map +3 -3
- package/dist/mjs/src/utils/flag-parser.mjs +132 -0
- package/dist/mjs/src/utils/flag-parser.mjs.map +10 -0
- package/dist/mjs/src/utils/index.mjs +6 -2
- package/dist/mjs/src/utils/index.mjs.map +3 -3
- package/dist/types/src/commands/colon/colon.d.ts +2 -0
- package/dist/types/src/commands/index.d.ts +1 -0
- package/dist/types/src/utils/flag-parser.d.ts +36 -0
- package/dist/types/src/utils/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ __export(exports_commands, {
|
|
|
51
51
|
echo: () => import_echo.echo,
|
|
52
52
|
cp: () => import_cp.cp,
|
|
53
53
|
continueCmd: () => import_break_continue.continueCmd,
|
|
54
|
+
colon: () => import_colon.colon,
|
|
54
55
|
cat: () => import_cat.cat,
|
|
55
56
|
builtinCommands: () => builtinCommands,
|
|
56
57
|
breakCmd: () => import_break_continue.breakCmd,
|
|
@@ -81,6 +82,7 @@ var import_find = require("./find/find.cjs");
|
|
|
81
82
|
var import_sed = require("./sed/sed.cjs");
|
|
82
83
|
var import_awk = require("./awk/awk.cjs");
|
|
83
84
|
var import_break_continue = require("./break-continue/break-continue.cjs");
|
|
85
|
+
var import_colon = require("./colon/colon.cjs");
|
|
84
86
|
var import_echo2 = require("./echo/echo.cjs");
|
|
85
87
|
var import_cat2 = require("./cat/cat.cjs");
|
|
86
88
|
var import_grep2 = require("./grep/grep.cjs");
|
|
@@ -104,6 +106,7 @@ var import_find2 = require("./find/find.cjs");
|
|
|
104
106
|
var import_sed2 = require("./sed/sed.cjs");
|
|
105
107
|
var import_awk2 = require("./awk/awk.cjs");
|
|
106
108
|
var import_break_continue2 = require("./break-continue/break-continue.cjs");
|
|
109
|
+
var import_colon2 = require("./colon/colon.cjs");
|
|
107
110
|
var builtinCommands = {
|
|
108
111
|
echo: import_echo2.echo,
|
|
109
112
|
cat: import_cat2.cat,
|
|
@@ -130,7 +133,8 @@ var builtinCommands = {
|
|
|
130
133
|
sed: import_sed2.sed,
|
|
131
134
|
awk: import_awk2.awk,
|
|
132
135
|
break: import_break_continue2.breakCmd,
|
|
133
|
-
continue: import_break_continue2.continueCmd
|
|
136
|
+
continue: import_break_continue2.continueCmd,
|
|
137
|
+
":": import_colon2.colon
|
|
134
138
|
};
|
|
135
139
|
|
|
136
|
-
//# debugId=
|
|
140
|
+
//# debugId=A797E42D013860AF64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/commands/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../types.cjs\";\n\nexport { echo } from \"./echo/echo.cjs\";\nexport { cat } from \"./cat/cat.cjs\";\nexport { grep } from \"./grep/grep.cjs\";\nexport { wc } from \"./wc/wc.cjs\";\nexport { head } from \"./head/head.cjs\";\nexport { tail } from \"./tail/tail.cjs\";\nexport { sort } from \"./sort/sort.cjs\";\nexport { uniq } from \"./uniq/uniq.cjs\";\nexport { pwd } from \"./pwd/pwd.cjs\";\nexport { ls } from \"./ls/ls.cjs\";\nexport { mkdir } from \"./mkdir/mkdir.cjs\";\nexport { rm } from \"./rm/rm.cjs\";\nexport { test, bracket } from \"./test/test.cjs\";\nexport { trueCmd, falseCmd } from \"./true-false/true-false.cjs\";\nexport { touch } from \"./touch/touch.cjs\";\nexport { cp } from \"./cp/cp.cjs\";\nexport { mv } from \"./mv/mv.cjs\";\nexport { tee } from \"./tee/tee.cjs\";\nexport { tree } from \"./tree/tree.cjs\";\nexport { find } from \"./find/find.cjs\";\nexport { sed } from \"./sed/sed.cjs\";\nexport { awk } from \"./awk/awk.cjs\";\nexport { breakCmd, continueCmd } from \"./break-continue/break-continue.cjs\";\n\n// Re-export all commands as a bundle\nimport { echo } from \"./echo/echo.cjs\";\nimport { cat } from \"./cat/cat.cjs\";\nimport { grep } from \"./grep/grep.cjs\";\nimport { wc } from \"./wc/wc.cjs\";\nimport { head } from \"./head/head.cjs\";\nimport { tail } from \"./tail/tail.cjs\";\nimport { sort } from \"./sort/sort.cjs\";\nimport { uniq } from \"./uniq/uniq.cjs\";\nimport { pwd } from \"./pwd/pwd.cjs\";\nimport { ls } from \"./ls/ls.cjs\";\nimport { mkdir } from \"./mkdir/mkdir.cjs\";\nimport { rm } from \"./rm/rm.cjs\";\nimport { test, bracket } from \"./test/test.cjs\";\nimport { trueCmd, falseCmd } from \"./true-false/true-false.cjs\";\nimport { touch } from \"./touch/touch.cjs\";\nimport { cp } from \"./cp/cp.cjs\";\nimport { mv } from \"./mv/mv.cjs\";\nimport { tee } from \"./tee/tee.cjs\";\nimport { tree } from \"./tree/tree.cjs\";\nimport { find } from \"./find/find.cjs\";\nimport { sed } from \"./sed/sed.cjs\";\nimport { awk } from \"./awk/awk.cjs\";\nimport { breakCmd, continueCmd } from \"./break-continue/break-continue.cjs\";\n\nexport const builtinCommands: Record<string, Command> = {\n echo,\n cat,\n grep,\n wc,\n head,\n tail,\n sort,\n uniq,\n pwd,\n ls,\n mkdir,\n rm,\n test,\n \"[\": bracket,\n true: trueCmd,\n false: falseCmd,\n touch,\n cp,\n mv,\n tee,\n tree,\n find,\n sed,\n awk,\n break: breakCmd,\n continue: continueCmd,\n};\n"
|
|
5
|
+
"import type { Command } from \"../types.cjs\";\n\nexport { echo } from \"./echo/echo.cjs\";\nexport { cat } from \"./cat/cat.cjs\";\nexport { grep } from \"./grep/grep.cjs\";\nexport { wc } from \"./wc/wc.cjs\";\nexport { head } from \"./head/head.cjs\";\nexport { tail } from \"./tail/tail.cjs\";\nexport { sort } from \"./sort/sort.cjs\";\nexport { uniq } from \"./uniq/uniq.cjs\";\nexport { pwd } from \"./pwd/pwd.cjs\";\nexport { ls } from \"./ls/ls.cjs\";\nexport { mkdir } from \"./mkdir/mkdir.cjs\";\nexport { rm } from \"./rm/rm.cjs\";\nexport { test, bracket } from \"./test/test.cjs\";\nexport { trueCmd, falseCmd } from \"./true-false/true-false.cjs\";\nexport { touch } from \"./touch/touch.cjs\";\nexport { cp } from \"./cp/cp.cjs\";\nexport { mv } from \"./mv/mv.cjs\";\nexport { tee } from \"./tee/tee.cjs\";\nexport { tree } from \"./tree/tree.cjs\";\nexport { find } from \"./find/find.cjs\";\nexport { sed } from \"./sed/sed.cjs\";\nexport { awk } from \"./awk/awk.cjs\";\nexport { breakCmd, continueCmd } from \"./break-continue/break-continue.cjs\";\nexport { colon } from \"./colon/colon.cjs\";\n\n// Re-export all commands as a bundle\nimport { echo } from \"./echo/echo.cjs\";\nimport { cat } from \"./cat/cat.cjs\";\nimport { grep } from \"./grep/grep.cjs\";\nimport { wc } from \"./wc/wc.cjs\";\nimport { head } from \"./head/head.cjs\";\nimport { tail } from \"./tail/tail.cjs\";\nimport { sort } from \"./sort/sort.cjs\";\nimport { uniq } from \"./uniq/uniq.cjs\";\nimport { pwd } from \"./pwd/pwd.cjs\";\nimport { ls } from \"./ls/ls.cjs\";\nimport { mkdir } from \"./mkdir/mkdir.cjs\";\nimport { rm } from \"./rm/rm.cjs\";\nimport { test, bracket } from \"./test/test.cjs\";\nimport { trueCmd, falseCmd } from \"./true-false/true-false.cjs\";\nimport { touch } from \"./touch/touch.cjs\";\nimport { cp } from \"./cp/cp.cjs\";\nimport { mv } from \"./mv/mv.cjs\";\nimport { tee } from \"./tee/tee.cjs\";\nimport { tree } from \"./tree/tree.cjs\";\nimport { find } from \"./find/find.cjs\";\nimport { sed } from \"./sed/sed.cjs\";\nimport { awk } from \"./awk/awk.cjs\";\nimport { breakCmd, continueCmd } from \"./break-continue/break-continue.cjs\";\nimport { colon } from \"./colon/colon.cjs\";\n\nexport const builtinCommands: Record<string, Command> = {\n echo,\n cat,\n grep,\n wc,\n head,\n tail,\n sort,\n uniq,\n pwd,\n ls,\n mkdir,\n rm,\n test,\n \"[\": bracket,\n true: trueCmd,\n false: falseCmd,\n touch,\n cp,\n mv,\n tee,\n tree,\n find,\n sed,\n awk,\n break: breakCmd,\n continue: continueCmd,\n \":\": colon,\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEqB,IAArB;AACoB,IAApB;AACqB,IAArB;AACmB,IAAnB;AACqB,IAArB;AACqB,IAArB;AACqB,IAArB;AACqB,IAArB;AACoB,IAApB;AACmB,IAAnB;AACsB,IAAtB;AACmB,IAAnB;AAC8B,IAA9B;AACkC,IAAlC;AACsB,IAAtB;AACmB,IAAnB;AACmB,IAAnB;AACoB,IAApB;AACqB,IAArB;AACqB,IAArB;AACoB,IAApB;AACoB,IAApB;AACsC,IAAtC;AACsB,IAAtB;AAGqB,IAArB;AACoB,IAApB;AACqB,IAArB;AACmB,IAAnB;AACqB,IAArB;AACqB,IAArB;AACqB,IAArB;AACqB,IAArB;AACoB,IAApB;AACmB,IAAnB;AACsB,IAAtB;AACmB,IAAnB;AAC8B,IAA9B;AACkC,IAAlC;AACsB,IAAtB;AACmB,IAAnB;AACmB,IAAnB;AACoB,IAApB;AACqB,IAArB;AACqB,IAArB;AACoB,IAApB;AACoB,IAApB;AACsC,IAAtC;AACsB,IAAtB;AAEO,IAAM,kBAA2C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,UAAU;AAAA,EACV,KAAK;AACP;",
|
|
8
|
+
"debugId": "A797E42D013860AF64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -32,34 +32,34 @@ __export(exports_ls, {
|
|
|
32
32
|
ls: () => ls
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_ls);
|
|
35
|
+
var import_flag_parser = require("../../utils/flag-parser.cjs");
|
|
36
|
+
var spec = {
|
|
37
|
+
name: "ls",
|
|
38
|
+
flags: [
|
|
39
|
+
{ short: "a", long: "all" },
|
|
40
|
+
{ short: "l" },
|
|
41
|
+
{ short: "1" }
|
|
42
|
+
],
|
|
43
|
+
usage: "ls [-al1] [file ...]"
|
|
44
|
+
};
|
|
45
|
+
var defaults = { all: false, long: false, onePerLine: false };
|
|
46
|
+
var handler = (flags, flag) => {
|
|
47
|
+
if (flag.short === "a")
|
|
48
|
+
flags.all = true;
|
|
49
|
+
if (flag.short === "l")
|
|
50
|
+
flags.long = true;
|
|
51
|
+
if (flag.short === "1")
|
|
52
|
+
flags.onePerLine = true;
|
|
53
|
+
};
|
|
54
|
+
var parser = import_flag_parser.createFlagParser(spec, defaults, handler);
|
|
35
55
|
var ls = async (ctx) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for (const arg of ctx.args) {
|
|
41
|
-
if (arg === "-a" || arg === "--all") {
|
|
42
|
-
showAll = true;
|
|
43
|
-
} else if (arg === "-l") {
|
|
44
|
-
longFormat = true;
|
|
45
|
-
} else if (arg === "-1") {
|
|
46
|
-
onePerLine = true;
|
|
47
|
-
} else if (arg.startsWith("-")) {
|
|
48
|
-
for (const flag of arg.slice(1)) {
|
|
49
|
-
if (flag === "a")
|
|
50
|
-
showAll = true;
|
|
51
|
-
else if (flag === "l")
|
|
52
|
-
longFormat = true;
|
|
53
|
-
else if (flag === "1")
|
|
54
|
-
onePerLine = true;
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
paths.push(arg);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (paths.length === 0) {
|
|
61
|
-
paths.push(".");
|
|
56
|
+
const result = parser.parse(ctx.args);
|
|
57
|
+
if (result.error) {
|
|
58
|
+
await parser.writeError(result.error, ctx.stderr);
|
|
59
|
+
return 1;
|
|
62
60
|
}
|
|
61
|
+
const { all: showAll, long: longFormat, onePerLine } = result.flags;
|
|
62
|
+
const paths = result.args.length === 0 ? ["."] : result.args;
|
|
63
63
|
for (let i = 0;i < paths.length; i++) {
|
|
64
64
|
const pathArg = paths[i];
|
|
65
65
|
const path = ctx.fs.resolve(ctx.cwd, pathArg);
|
|
@@ -116,4 +116,4 @@ var ls = async (ctx) => {
|
|
|
116
116
|
return 0;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
//# debugId=
|
|
119
|
+
//# debugId=4890CAC52EAF1A2264756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/ls/ls.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface LsFlags {\n all: boolean;\n long: boolean;\n onePerLine: boolean;\n}\n\nconst spec = {\n name: \"ls\",\n flags: [\n { short: \"a\", long: \"all\" },\n { short: \"l\" },\n { short: \"1\" },\n ] as FlagDefinition[],\n usage: \"ls [-al1] [file ...]\",\n};\n\nconst defaults: LsFlags = { all: false, long: false, onePerLine: false };\n\nconst handler = (flags: LsFlags, flag: FlagDefinition) => {\n if (flag.short === \"a\") flags.all = true;\n if (flag.short === \"l\") flags.long = true;\n if (flag.short === \"1\") flags.onePerLine = true;\n};\n\nconst parser = createFlagParser(spec, defaults, handler);\n\nexport const ls: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const { all: showAll, long: longFormat, onePerLine } = result.flags;\n const paths = result.args.length === 0 ? [\".\"] : result.args;\n\n for (let i = 0; i < paths.length; i++) {\n const pathArg = paths[i]!;\n const path = ctx.fs.resolve(ctx.cwd, pathArg);\n\n try {\n const stat = await ctx.fs.stat(path);\n\n if (stat.isFile()) {\n // It's a file, just print the name\n await ctx.stdout.writeText(ctx.fs.basename(path) + \"\\n\");\n continue;\n }\n\n // It's a directory\n if (paths.length > 1) {\n if (i > 0) await ctx.stdout.writeText(\"\\n\");\n await ctx.stdout.writeText(`${pathArg}:\\n`);\n }\n\n let entries = await ctx.fs.readdir(path);\n\n if (!showAll) {\n entries = entries.filter((e) => !e.startsWith(\".\"));\n }\n\n entries.sort();\n\n if (longFormat) {\n for (const entry of entries) {\n const entryPath = ctx.fs.resolve(path, entry);\n try {\n const entryStat = await ctx.fs.stat(entryPath);\n const type = entryStat.isDirectory() ? \"d\" : \"-\";\n const perms = \"rwxr-xr-x\"; // Simplified permissions\n const size = String(entryStat.size).padStart(8);\n const date = entryStat.mtime.toISOString().slice(0, 10);\n await ctx.stdout.writeText(`${type}${perms} ${size} ${date} ${entry}\\n`);\n } catch {\n await ctx.stdout.writeText(`?????????? ${entry}\\n`);\n }\n }\n } else if (onePerLine) {\n for (const entry of entries) {\n await ctx.stdout.writeText(entry + \"\\n\");\n }\n } else {\n // Default: space-separated\n await ctx.stdout.writeText(entries.join(\" \") + \"\\n\");\n }\n } catch (err) {\n await ctx.stderr.writeText(`ls: cannot access '${pathArg}': No such file or directory\\n`);\n return 1;\n }\n }\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;AAQA,IAAM,OAAO;AAAA,EACX,MAA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ugId": "4890CAC52EAF1A2264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -32,16 +32,27 @@ __export(exports_mkdir, {
|
|
|
32
32
|
mkdir: () => mkdir
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_mkdir);
|
|
35
|
+
var import_flag_parser = require("../../utils/flag-parser.cjs");
|
|
36
|
+
var spec = {
|
|
37
|
+
name: "mkdir",
|
|
38
|
+
flags: [
|
|
39
|
+
{ short: "p", long: "parents" }
|
|
40
|
+
],
|
|
41
|
+
usage: "mkdir [-p] directory ..."
|
|
42
|
+
};
|
|
43
|
+
var defaults = { parents: false };
|
|
44
|
+
var handler = (flags, flag) => {
|
|
45
|
+
if (flag.short === "p")
|
|
46
|
+
flags.parents = true;
|
|
47
|
+
};
|
|
48
|
+
var parser = import_flag_parser.createFlagParser(spec, defaults, handler);
|
|
35
49
|
var mkdir = async (ctx) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
parents = true;
|
|
41
|
-
} else if (!arg.startsWith("-")) {
|
|
42
|
-
dirs.push(arg);
|
|
43
|
-
}
|
|
50
|
+
const result = parser.parse(ctx.args);
|
|
51
|
+
if (result.error) {
|
|
52
|
+
await parser.writeError(result.error, ctx.stderr);
|
|
53
|
+
return 1;
|
|
44
54
|
}
|
|
55
|
+
const dirs = result.args;
|
|
45
56
|
if (dirs.length === 0) {
|
|
46
57
|
await ctx.stderr.writeText(`mkdir: missing operand
|
|
47
58
|
`);
|
|
@@ -50,7 +61,7 @@ var mkdir = async (ctx) => {
|
|
|
50
61
|
for (const dir of dirs) {
|
|
51
62
|
const path = ctx.fs.resolve(ctx.cwd, dir);
|
|
52
63
|
try {
|
|
53
|
-
await ctx.fs.mkdir(path, { recursive: parents });
|
|
64
|
+
await ctx.fs.mkdir(path, { recursive: result.flags.parents });
|
|
54
65
|
} catch (err) {
|
|
55
66
|
const message = err instanceof Error ? err.message : String(err);
|
|
56
67
|
await ctx.stderr.writeText(`mkdir: cannot create directory '${dir}': ${message}
|
|
@@ -61,4 +72,4 @@ var mkdir = async (ctx) => {
|
|
|
61
72
|
return 0;
|
|
62
73
|
};
|
|
63
74
|
|
|
64
|
-
//# debugId=
|
|
75
|
+
//# debugId=20ED31C829967E7364756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/mkdir/mkdir.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface MkdirFlags {\n parents: boolean;\n}\n\nconst spec = {\n name: \"mkdir\",\n flags: [\n { short: \"p\", long: \"parents\" },\n ] as FlagDefinition[],\n usage: \"mkdir [-p] directory ...\",\n};\n\nconst defaults: MkdirFlags = { parents: false };\n\nconst handler = (flags: MkdirFlags, flag: FlagDefinition) => {\n if (flag.short === \"p\") flags.parents = true;\n};\n\nconst parser = createFlagParser(spec, defaults, handler);\n\nexport const mkdir: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const dirs = result.args;\n\n if (dirs.length === 0) {\n await ctx.stderr.writeText(\"mkdir: missing operand\\n\");\n return 1;\n }\n\n for (const dir of dirs) {\n const path = ctx.fs.resolve(ctx.cwd, dir);\n try {\n await ctx.fs.mkdir(path, { recursive: result.flags.parents });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`mkdir: cannot create directory '${dir}': ${message}\\n`);\n return 1;\n }\n }\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;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33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_mv);
|
|
35
|
+
var import_flag_parser = require("../../utils/flag-parser.cjs");
|
|
36
|
+
var spec = {
|
|
37
|
+
name: "mv",
|
|
38
|
+
flags: [
|
|
39
|
+
{ short: "n", long: "no-clobber" },
|
|
40
|
+
{ short: "f", long: "force" }
|
|
41
|
+
],
|
|
42
|
+
usage: "mv [-nf] source ... dest"
|
|
43
|
+
};
|
|
44
|
+
var defaults = { noClobber: false };
|
|
45
|
+
var handler = (flags, flag) => {
|
|
46
|
+
if (flag.short === "n")
|
|
47
|
+
flags.noClobber = true;
|
|
48
|
+
};
|
|
49
|
+
var parser = import_flag_parser.createFlagParser(spec, defaults, handler);
|
|
35
50
|
var mv = async (ctx) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
noClobber = true;
|
|
41
|
-
} else if (arg === "-f" || arg === "--force") {} else if (arg.startsWith("-")) {
|
|
42
|
-
for (const flag of arg.slice(1)) {
|
|
43
|
-
if (flag === "n")
|
|
44
|
-
noClobber = true;
|
|
45
|
-
else if (flag === "f") {}
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
paths.push(arg);
|
|
49
|
-
}
|
|
51
|
+
const result = parser.parse(ctx.args);
|
|
52
|
+
if (result.error) {
|
|
53
|
+
await parser.writeError(result.error, ctx.stderr);
|
|
54
|
+
return 1;
|
|
50
55
|
}
|
|
56
|
+
const { noClobber } = result.flags;
|
|
57
|
+
const paths = result.args;
|
|
51
58
|
if (paths.length < 2) {
|
|
52
59
|
await ctx.stderr.writeText(`mv: missing destination file operand
|
|
53
60
|
`);
|
|
@@ -115,4 +122,4 @@ async function moveDirectory(ctx, src, dest, noClobber) {
|
|
|
115
122
|
await ctx.fs.rm(src, { recursive: true });
|
|
116
123
|
}
|
|
117
124
|
|
|
118
|
-
//# debugId=
|
|
125
|
+
//# debugId=8A90C10112D65AC464756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/mv/mv.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface MvFlags {\n noClobber: boolean;\n}\n\nconst spec = {\n name: \"mv\",\n flags: [\n { short: \"n\", long: \"no-clobber\" },\n { short: \"f\", long: \"force\" },\n ] as FlagDefinition[],\n usage: \"mv [-nf] source ... dest\",\n};\n\nconst defaults: MvFlags = { noClobber: false };\n\nconst handler = (flags: MvFlags, flag: FlagDefinition) => {\n if (flag.short === \"n\") flags.noClobber = true;\n // -f is default behavior, so we don't need to do anything\n};\n\nconst parser = createFlagParser(spec, defaults, handler);\n\nexport const mv: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const { noClobber } = result.flags;\n const paths = result.args;\n\n if (paths.length < 2) {\n await ctx.stderr.writeText(\"mv: missing destination file operand\\n\");\n return 1;\n }\n\n const sources = paths.slice(0, -1);\n const dest = paths[paths.length - 1]!;\n const destPath = ctx.fs.resolve(ctx.cwd, dest);\n\n // Check if destination is a directory\n let destIsDir = false;\n try {\n const stat = await ctx.fs.stat(destPath);\n destIsDir = stat.isDirectory();\n } catch {\n // Destination doesn't exist\n }\n\n // If multiple sources, dest must be a directory\n if (sources.length > 1 && !destIsDir) {\n await ctx.stderr.writeText(`mv: target '${dest}' is not a directory\\n`);\n return 1;\n }\n\n for (const source of sources) {\n const srcPath = ctx.fs.resolve(ctx.cwd, source);\n\n try {\n // Check source exists\n await ctx.fs.stat(srcPath);\n\n // Determine final destination path\n const finalDest = destIsDir\n ? ctx.fs.resolve(destPath, ctx.fs.basename(srcPath))\n : destPath;\n\n // Check if dest exists and noClobber\n if (noClobber) {\n const exists = await ctx.fs.exists(finalDest);\n if (exists) continue; // Skip silently\n }\n\n // Move: copy then delete\n const srcStat = await ctx.fs.stat(srcPath);\n if (srcStat.isDirectory()) {\n await moveDirectory(ctx, srcPath, finalDest, noClobber);\n } else {\n const content = await ctx.fs.readFile(srcPath);\n await ctx.fs.writeFile(finalDest, content);\n await ctx.fs.rm(srcPath);\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`mv: cannot stat '${source}': ${message}\\n`);\n return 1;\n }\n }\n\n return 0;\n};\n\nasync function moveDirectory(\n ctx: Parameters<Command>[0],\n src: string,\n dest: string,\n noClobber: boolean\n): Promise<void> {\n // Create destination directory\n await ctx.fs.mkdir(dest, { recursive: true });\n\n // Read source directory contents\n const entries = await ctx.fs.readdir(src);\n\n for (const entry of entries) {\n const srcPath = ctx.fs.resolve(src, entry);\n const destPath = ctx.fs.resolve(dest, entry);\n\n const stat = await ctx.fs.stat(srcPath);\n\n if (stat.isDirectory()) {\n await moveDirectory(ctx, srcPath, destPath, noClobber);\n } else {\n if (noClobber) {\n const exists = await ctx.fs.exists(destPath);\n if (exists) continue;\n }\n const content = await ctx.fs.readFile(srcPath);\n await ctx.fs.writeFile(destPath, content);\n }\n }\n\n // Remove source directory after copying\n await ctx.fs.rm(src, { recursive: true });\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;AAMA,IAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,IACL,EAAE,OAAO,KAAK,MAAM,aAAa;AAAA,IACjC,EAAE,OAAO,KAAK,MAAM,QAAQ;AAAA,EAC9B;AAAA,EACA,OAAO;AACT;AAEA,IAAM,WAAoB,EAAE,WAAW,MAAM;AAE7C,IAAM,UAAU,CAAC,OAAgB,SAAyB;AAAA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UAAU,UAAU,OAAO;AAAA;AAAA,EAE5C;AAAA,EAGA,MAAM,IAAI,GAAG,GAAG,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA;",
|
|
8
|
+
"debugId": "8A90C10112D65AC464756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -32,10 +32,22 @@ __export(exports_pwd, {
|
|
|
32
32
|
pwd: () => pwd
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_pwd);
|
|
35
|
+
var import_flag_parser = require("../../utils/flag-parser.cjs");
|
|
36
|
+
var spec = {
|
|
37
|
+
name: "pwd",
|
|
38
|
+
flags: [],
|
|
39
|
+
usage: "pwd"
|
|
40
|
+
};
|
|
41
|
+
var parser = import_flag_parser.createFlagParser(spec, {}, () => {});
|
|
35
42
|
var pwd = async (ctx) => {
|
|
43
|
+
const result = parser.parse(ctx.args);
|
|
44
|
+
if (result.error) {
|
|
45
|
+
await parser.writeError(result.error, ctx.stderr);
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
36
48
|
await ctx.stdout.writeText(ctx.cwd + `
|
|
37
49
|
`);
|
|
38
50
|
return 0;
|
|
39
51
|
};
|
|
40
52
|
|
|
41
|
-
//# debugId=
|
|
53
|
+
//# debugId=E85D963E473EBB6F64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/pwd/pwd.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\n\nexport const pwd: Command = async (ctx) => {\n await ctx.stdout.writeText(ctx.cwd + \"\\n\");\n return 0;\n};\n"
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\nconst spec = {\n name: \"pwd\",\n flags: [] as FlagDefinition[],\n usage: \"pwd\",\n};\n\nconst parser = createFlagParser(spec, {}, () => {});\n\nexport const pwd: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n await ctx.stdout.writeText(ctx.cwd + \"\\n\");\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;AAEA,IAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,OAAO,CAAC;AAAA,EACR,OAAO;AACT;AAEA,IAAM,SAAS,oCAAiB,MAAM,CAAC,GAAG,MAAM,EAAE;AAE3C,IAAM,MAAe,OAAO,QAAQ;AAAA,EACzC,MAAM,SAAS,OAAO,MAAM,IAAI,IAAI;AAAA,EAEpC,IAAI,OAAO,OAAO;AAAA,IAChB,MAAM,OAAO,WAAW,OAAO,OAAO,IAAI,MAAM;AAAA,IAChD,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,IAAI,OAAO,UAAU,IAAI,MAAM;AAAA,CAAI;AAAA,EACzC,OAAO;AAAA;",
|
|
8
|
+
"debugId": "E85D963E473EBB6F64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -32,29 +32,32 @@ __export(exports_rm, {
|
|
|
32
32
|
rm: () => rm
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_rm);
|
|
35
|
+
var import_flag_parser = require("../../utils/flag-parser.cjs");
|
|
36
|
+
var spec = {
|
|
37
|
+
name: "rm",
|
|
38
|
+
flags: [
|
|
39
|
+
{ short: "r", long: "recursive" },
|
|
40
|
+
{ short: "R" },
|
|
41
|
+
{ short: "f", long: "force" }
|
|
42
|
+
],
|
|
43
|
+
usage: "rm [-rf] file ..."
|
|
44
|
+
};
|
|
45
|
+
var defaults = { recursive: false, force: false };
|
|
46
|
+
var handler = (flags, flag) => {
|
|
47
|
+
if (flag.short === "r" || flag.short === "R")
|
|
48
|
+
flags.recursive = true;
|
|
49
|
+
if (flag.short === "f")
|
|
50
|
+
flags.force = true;
|
|
51
|
+
};
|
|
52
|
+
var parser = import_flag_parser.createFlagParser(spec, defaults, handler);
|
|
35
53
|
var rm = async (ctx) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (arg === "-r" || arg === "-R" || arg === "--recursive") {
|
|
41
|
-
recursive = true;
|
|
42
|
-
} else if (arg === "-f" || arg === "--force") {
|
|
43
|
-
force = true;
|
|
44
|
-
} else if (arg === "-rf" || arg === "-fr") {
|
|
45
|
-
recursive = true;
|
|
46
|
-
force = true;
|
|
47
|
-
} else if (arg.startsWith("-")) {
|
|
48
|
-
for (const flag of arg.slice(1)) {
|
|
49
|
-
if (flag === "r" || flag === "R")
|
|
50
|
-
recursive = true;
|
|
51
|
-
else if (flag === "f")
|
|
52
|
-
force = true;
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
targets.push(arg);
|
|
56
|
-
}
|
|
54
|
+
const result = parser.parse(ctx.args);
|
|
55
|
+
if (result.error) {
|
|
56
|
+
await parser.writeError(result.error, ctx.stderr);
|
|
57
|
+
return 1;
|
|
57
58
|
}
|
|
59
|
+
const { recursive, force } = result.flags;
|
|
60
|
+
const targets = result.args;
|
|
58
61
|
if (targets.length === 0) {
|
|
59
62
|
if (!force) {
|
|
60
63
|
await ctx.stderr.writeText(`rm: missing operand
|
|
@@ -79,4 +82,4 @@ var rm = async (ctx) => {
|
|
|
79
82
|
return 0;
|
|
80
83
|
};
|
|
81
84
|
|
|
82
|
-
//# debugId=
|
|
85
|
+
//# debugId=E8259020AB1AC90264756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/rm/rm.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\nimport { createFlagParser, type FlagDefinition } from \"../../utils/flag-parser.cjs\";\n\ninterface RmFlags {\n recursive: boolean;\n force: boolean;\n}\n\nconst spec = {\n name: \"rm\",\n flags: [\n { short: \"r\", long: \"recursive\" },\n { short: \"R\" },\n { short: \"f\", long: \"force\" },\n ] as FlagDefinition[],\n usage: \"rm [-rf] file ...\",\n};\n\nconst defaults: RmFlags = { recursive: false, force: false };\n\nconst handler = (flags: RmFlags, flag: FlagDefinition) => {\n if (flag.short === \"r\" || flag.short === \"R\") flags.recursive = true;\n if (flag.short === \"f\") flags.force = true;\n};\n\nconst parser = createFlagParser(spec, defaults, handler);\n\nexport const rm: Command = async (ctx) => {\n const result = parser.parse(ctx.args);\n\n if (result.error) {\n await parser.writeError(result.error, ctx.stderr);\n return 1;\n }\n\n const { recursive, force } = result.flags;\n const targets = result.args;\n\n if (targets.length === 0) {\n if (!force) {\n await ctx.stderr.writeText(\"rm: missing operand\\n\");\n return 1;\n }\n return 0;\n }\n\n for (const target of targets) {\n const path = ctx.fs.resolve(ctx.cwd, target);\n try {\n await ctx.fs.rm(path, { recursive, force });\n } catch (err) {\n if (!force) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`rm: cannot remove '${target}': ${message}\\n`);\n return 1;\n }\n }\n }\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACsD,IAAtD;AAOA,IAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,IACL,EAAE,OAAO,KAAK,MAAM,YAAY;AAAA,IAChC,EAAE,OAAO,IAAI;AAAA,IACb,EAAE,OAAO,KAAK,MAAM,QAAQ;AAAA,EAC9B;AAAA,EACA,OAAO;AACT;AAEA,IAAM,WAAoB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|
|
147
147
|
let i = 0;
|
|
148
148
|
while (i < args.length) {
|
|
149
149
|
const arg = args[i];
|
|
150
|
-
if (arg === "
|
|
151
|
-
options.suppressOutput = true;
|
|
150
|
+
if (arg === "--") {
|
|
152
151
|
i++;
|
|
153
|
-
|
|
152
|
+
while (i < args.length) {
|
|
153
|
+
const remaining = args[i];
|
|
154
|
+
if (options.commands.length === 0) {
|
|
155
|
+
const parts = splitScriptParts(remaining);
|
|
156
|
+
for (const part of parts) {
|
|
157
|
+
const cmd = parseCommand(part);
|
|
158
|
+
if (cmd)
|
|
159
|
+
options.commands.push(cmd);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
files.push(remaining);
|
|
163
|
+
}
|
|
164
|
+
i++;
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
154
167
|
}
|
|
155
|
-
if (arg
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
if (arg.startsWith("--")) {
|
|
169
|
+
return {
|
|
170
|
+
options,
|
|
171
|
+
files,
|
|
172
|
+
error: { type: "unrecognized_option", option: arg }
|
|
173
|
+
};
|
|
159
174
|
}
|
|
160
|
-
if (arg
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
175
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
176
|
+
const flagChars = arg.slice(1);
|
|
177
|
+
for (let j = 0;j < flagChars.length; j++) {
|
|
178
|
+
const char = flagChars[j];
|
|
179
|
+
if (char === "n") {
|
|
180
|
+
options.suppressOutput = true;
|
|
181
|
+
} else if (char === "i") {
|
|
182
|
+
options.inPlace = true;
|
|
183
|
+
} else if (char === "e") {
|
|
184
|
+
const restOfArg = flagChars.slice(j + 1);
|
|
185
|
+
let script;
|
|
186
|
+
if (restOfArg.length > 0) {
|
|
187
|
+
script = restOfArg;
|
|
188
|
+
} else if (i + 1 < args.length) {
|
|
189
|
+
script = args[++i];
|
|
190
|
+
} else {
|
|
191
|
+
return {
|
|
192
|
+
options,
|
|
193
|
+
files,
|
|
194
|
+
error: { type: "missing_value", option: "-e" }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const cmd = parseCommand(script);
|
|
198
|
+
if (cmd)
|
|
199
|
+
options.commands.push(cmd);
|
|
200
|
+
break;
|
|
201
|
+
} else {
|
|
202
|
+
return {
|
|
203
|
+
options,
|
|
204
|
+
files,
|
|
205
|
+
error: { type: "unrecognized_option", option: `-${char}` }
|
|
206
|
+
};
|
|
207
|
+
}
|
|
164
208
|
}
|
|
165
|
-
i
|
|
209
|
+
i++;
|
|
166
210
|
continue;
|
|
167
211
|
}
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
options.commands.push(cmd);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
files.push(arg);
|
|
212
|
+
if (options.commands.length === 0) {
|
|
213
|
+
const parts = splitScriptParts(arg);
|
|
214
|
+
for (const part of parts) {
|
|
215
|
+
const cmd = parseCommand(part);
|
|
216
|
+
if (cmd)
|
|
217
|
+
options.commands.push(cmd);
|
|
179
218
|
}
|
|
219
|
+
} else {
|
|
220
|
+
files.push(arg);
|
|
180
221
|
}
|
|
181
222
|
i++;
|
|
182
223
|
}
|
|
183
224
|
return { options, files };
|
|
184
225
|
}
|
|
226
|
+
function formatError(error) {
|
|
227
|
+
let message;
|
|
228
|
+
if (error.type === "unrecognized_option") {
|
|
229
|
+
if (error.option.startsWith("--")) {
|
|
230
|
+
message = `sed: unrecognized option '${error.option}'
|
|
231
|
+
`;
|
|
232
|
+
} else {
|
|
233
|
+
message = `sed: invalid option -- '${error.option.slice(1)}'
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
message = `sed: option '${error.option}' requires an argument
|
|
238
|
+
`;
|
|
239
|
+
}
|
|
240
|
+
return message + `usage: sed [-ni] [-e script] script [file ...]
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
185
243
|
function applySubstitution(line, cmd) {
|
|
186
244
|
if (!cmd.pattern)
|
|
187
245
|
return line;
|
|
@@ -224,7 +282,11 @@ function processLine(line, commands, suppressOutput) {
|
|
|
224
282
|
return { output: currentLine, deleted: false };
|
|
225
283
|
}
|
|
226
284
|
var sed = async (ctx) => {
|
|
227
|
-
const { options, files } = parseArgs(ctx.args);
|
|
285
|
+
const { options, files, error } = parseArgs(ctx.args);
|
|
286
|
+
if (error) {
|
|
287
|
+
await ctx.stderr.writeText(formatError(error));
|
|
288
|
+
return 1;
|
|
289
|
+
}
|
|
228
290
|
if (options.commands.length === 0) {
|
|
229
291
|
await ctx.stderr.writeText(`sed: missing script
|
|
230
292
|
`);
|
|
@@ -292,4 +354,4 @@ var sed = async (ctx) => {
|
|
|
292
354
|
return 0;
|
|
293
355
|
};
|
|
294
356
|
|
|
295
|
-
//# debugId=
|
|
357
|
+
//# debugId=9484A386918DB8C764756E2164756E21
|