@poe-platform/safe-bash 0.1.756 → 0.1.757
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/image-ast/index.browser.js +4 -4
- package/dist/image-ast/index.js +4 -4
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-soffice/index.js +16 -16
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +107 -27
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +2 -2
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
|
@@ -1,843 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
builtInDirectContextExecutors
|
|
3
|
-
} from "./chunk-ISCZG7WA.js";
|
|
4
|
-
import {
|
|
5
|
-
init_platform
|
|
6
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
7
|
-
|
|
8
|
-
// packages/safe-bash/src/commands/getopt/index.ts
|
|
9
|
-
init_platform();
|
|
10
|
-
|
|
11
|
-
// packages/safe-bash-command-getopt/src/index.ts
|
|
12
|
-
init_platform();
|
|
13
|
-
|
|
14
|
-
// packages/safe-bash-command-getopt/src/command.ts
|
|
15
|
-
init_platform();
|
|
16
|
-
import { createOutputOperation } from "../../safe-bash-contracts/output.js";
|
|
17
|
-
|
|
18
|
-
// packages/safe-bash-command-getopt/src/internal.ts
|
|
19
|
-
init_platform();
|
|
20
|
-
import { getCommandArguments } from "../../safe-bash-contracts/index.js";
|
|
21
|
-
import { shellValueByteLength, shellValueBytes } from "../../safe-bash-contracts/value.js";
|
|
22
|
-
import { yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
23
|
-
import { PublicDiagnostic } from "../../safe-bash-contracts/diagnostics.js";
|
|
24
|
-
function settings(options) {
|
|
25
|
-
const limits = {
|
|
26
|
-
maxArguments: Infinity,
|
|
27
|
-
maxArgumentBytes: Infinity,
|
|
28
|
-
maxInputBytes: Infinity,
|
|
29
|
-
maxSchemaBytes: Infinity,
|
|
30
|
-
maxLongOptions: Infinity,
|
|
31
|
-
maxBufferedBytes: Infinity,
|
|
32
|
-
maxOutputBytes: Infinity,
|
|
33
|
-
maxDiagnosticBytes: Infinity,
|
|
34
|
-
maxWork: Infinity,
|
|
35
|
-
...options.limits
|
|
36
|
-
};
|
|
37
|
-
for (const [name, value] of Object.entries(limits)) {
|
|
38
|
-
if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) throw new RangeError(`Invalid getopt limit: ${name}`);
|
|
39
|
-
}
|
|
40
|
-
return Object.freeze(limits);
|
|
41
|
-
}
|
|
42
|
-
var GetoptError = class extends PublicDiagnostic {
|
|
43
|
-
constructor(message, status = 3, usage = false) {
|
|
44
|
-
super(message);
|
|
45
|
-
this.status = status;
|
|
46
|
-
this.usage = usage;
|
|
47
|
-
}
|
|
48
|
-
status;
|
|
49
|
-
usage;
|
|
50
|
-
};
|
|
51
|
-
var Budget = class {
|
|
52
|
-
constructor(context, limits, signal) {
|
|
53
|
-
this.context = context;
|
|
54
|
-
this.limits = limits;
|
|
55
|
-
this.signal = signal;
|
|
56
|
-
}
|
|
57
|
-
context;
|
|
58
|
-
limits;
|
|
59
|
-
signal;
|
|
60
|
-
work = 0;
|
|
61
|
-
quantum = 0;
|
|
62
|
-
retained = 0;
|
|
63
|
-
diagnosticRetained = 0;
|
|
64
|
-
schemaBytes = 0;
|
|
65
|
-
output = 0;
|
|
66
|
-
diagnostics = 0;
|
|
67
|
-
check(value, maximum, label) {
|
|
68
|
-
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) throw new GetoptError(`${label} limit exceeded`);
|
|
69
|
-
}
|
|
70
|
-
async step(amount = 1, diagnostic = false) {
|
|
71
|
-
this.signal.throwIfAborted();
|
|
72
|
-
if (!diagnostic) {
|
|
73
|
-
this.check(this.work + amount, this.limits.maxWork, "work");
|
|
74
|
-
this.work += amount;
|
|
75
|
-
}
|
|
76
|
-
this.quantum += amount;
|
|
77
|
-
if (this.quantum >= 1024) {
|
|
78
|
-
this.quantum = 0;
|
|
79
|
-
await yieldTurn(this.signal);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
retain(amount, diagnostic = false) {
|
|
83
|
-
if (diagnostic) {
|
|
84
|
-
this.check(this.diagnosticRetained + amount, this.limits.maxDiagnosticBytes, "diagnostic buffered bytes");
|
|
85
|
-
this.diagnosticRetained += amount;
|
|
86
|
-
} else {
|
|
87
|
-
this.check(this.retained + amount, this.limits.maxBufferedBytes, "buffered bytes");
|
|
88
|
-
this.retained += amount;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
schema(amount) {
|
|
92
|
-
this.check(this.schemaBytes + amount, this.limits.maxSchemaBytes, "schema bytes");
|
|
93
|
-
this.schemaBytes += amount;
|
|
94
|
-
}
|
|
95
|
-
room(amount, diagnostic = false) {
|
|
96
|
-
this.check(
|
|
97
|
-
(diagnostic ? this.diagnostics : this.output) + amount,
|
|
98
|
-
diagnostic ? this.limits.maxDiagnosticBytes : this.limits.maxOutputBytes,
|
|
99
|
-
diagnostic ? "diagnostic bytes" : "output bytes"
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
emitted(amount, diagnostic) {
|
|
103
|
-
this.room(amount, diagnostic);
|
|
104
|
-
if (diagnostic) this.diagnostics += amount;
|
|
105
|
-
else this.output += amount;
|
|
106
|
-
}
|
|
107
|
-
async arguments() {
|
|
108
|
-
const args = this.context.args;
|
|
109
|
-
this.signal.throwIfAborted();
|
|
110
|
-
this.check(args.length, this.limits.maxArguments, "argument count");
|
|
111
|
-
let total = 0;
|
|
112
|
-
for (const argument of args) {
|
|
113
|
-
this.check(argument.length, this.limits.maxArgumentBytes, "argument bytes");
|
|
114
|
-
total += argument.length;
|
|
115
|
-
this.check(total, this.limits.maxInputBytes, "input bytes");
|
|
116
|
-
for (let offset = 0; offset < argument.length; offset++) {
|
|
117
|
-
await this.step();
|
|
118
|
-
const unit = argument.charCodeAt(offset);
|
|
119
|
-
if (unit >= 55296 && unit <= 56319) {
|
|
120
|
-
const next = argument.charCodeAt(++offset);
|
|
121
|
-
if (!(next >= 56320 && next <= 57343)) throw new GetoptError("arguments must contain well-formed Unicode", 2);
|
|
122
|
-
} else if (unit >= 56320 && unit <= 57343) throw new GetoptError("arguments must contain well-formed Unicode", 2);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const values = this.context.argumentValues === void 0 ? args : getCommandArguments(this.context).values;
|
|
126
|
-
total = 0;
|
|
127
|
-
for (const argument of values) {
|
|
128
|
-
await this.step();
|
|
129
|
-
const size = shellValueByteLength(argument);
|
|
130
|
-
this.check(size, this.limits.maxArgumentBytes, "argument bytes");
|
|
131
|
-
total += size;
|
|
132
|
-
this.check(total, this.limits.maxInputBytes, "input bytes");
|
|
133
|
-
}
|
|
134
|
-
this.retain(total * 8 + args.length * 64 + 256);
|
|
135
|
-
this.signal.throwIfAborted();
|
|
136
|
-
const owned = getCommandArguments(this.context).values;
|
|
137
|
-
const result = [];
|
|
138
|
-
for (const argument of owned) {
|
|
139
|
-
await this.step();
|
|
140
|
-
const value = shellValueBytes(argument);
|
|
141
|
-
let text = "";
|
|
142
|
-
for (let offset = 0; offset < value.length; offset += 256) {
|
|
143
|
-
const end = Math.min(offset + 256, value.length);
|
|
144
|
-
for (let index = offset; index < end; index++) {
|
|
145
|
-
await this.step();
|
|
146
|
-
if (value[index] === 0) throw new GetoptError("NUL is not supported in arguments", 2);
|
|
147
|
-
}
|
|
148
|
-
text += String.fromCharCode(...value.subarray(offset, end));
|
|
149
|
-
}
|
|
150
|
-
result.push(text);
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// packages/safe-bash-command-getopt/src/io.ts
|
|
157
|
-
init_platform();
|
|
158
|
-
var Writer = class {
|
|
159
|
-
constructor(budget, output) {
|
|
160
|
-
this.budget = budget;
|
|
161
|
-
output.registerCleanup(() => this.close());
|
|
162
|
-
}
|
|
163
|
-
budget;
|
|
164
|
-
pending = /* @__PURE__ */ new Set();
|
|
165
|
-
closing;
|
|
166
|
-
assertOpen() {
|
|
167
|
-
this.budget.signal.throwIfAborted();
|
|
168
|
-
if (this.closing) throw new GetoptError("command is closed");
|
|
169
|
-
}
|
|
170
|
-
close() {
|
|
171
|
-
return this.closing ??= Promise.resolve().then(async () => {
|
|
172
|
-
while (this.pending.size) await Promise.allSettled([...this.pending]);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
async publish(length, diagnostic, fill) {
|
|
176
|
-
this.assertOpen();
|
|
177
|
-
this.budget.emitted(length, diagnostic);
|
|
178
|
-
this.budget.retain(length, diagnostic);
|
|
179
|
-
const pending = Promise.resolve().then(async () => {
|
|
180
|
-
this.assertOpen();
|
|
181
|
-
const buffer = new Uint8Array(length);
|
|
182
|
-
await fill(buffer);
|
|
183
|
-
this.assertOpen();
|
|
184
|
-
const sink = diagnostic ? this.budget.context.stderr : this.budget.context.stdout;
|
|
185
|
-
this.assertOpen();
|
|
186
|
-
const destination = sink.ownedOutput ?? sink;
|
|
187
|
-
this.assertOpen();
|
|
188
|
-
const write = destination.write;
|
|
189
|
-
this.assertOpen();
|
|
190
|
-
await Reflect.apply(write, destination, [buffer]);
|
|
191
|
-
});
|
|
192
|
-
this.pending.add(pending);
|
|
193
|
-
try {
|
|
194
|
-
await pending;
|
|
195
|
-
this.assertOpen();
|
|
196
|
-
} finally {
|
|
197
|
-
this.pending.delete(pending);
|
|
198
|
-
this.budget.retain(-length, diagnostic);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async send(parts, diagnostic = false) {
|
|
202
|
-
let length = 0;
|
|
203
|
-
for (const part of parts) {
|
|
204
|
-
await this.budget.step(1, diagnostic);
|
|
205
|
-
length += part.length;
|
|
206
|
-
this.budget.room(length, diagnostic);
|
|
207
|
-
}
|
|
208
|
-
await this.publish(length, diagnostic, async (buffer) => {
|
|
209
|
-
let offset = 0;
|
|
210
|
-
for (const part of parts) for (let index = 0; index < part.length; index++) {
|
|
211
|
-
await this.budget.step(1, diagnostic);
|
|
212
|
-
buffer[offset++] = part.charCodeAt(index);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
async normalized(value, quote, tcsh) {
|
|
217
|
-
if (!quote) {
|
|
218
|
-
await this.send([" ", value]);
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
let length = 3;
|
|
222
|
-
for (let offset = 0; offset < value.length; offset++) {
|
|
223
|
-
await this.budget.step();
|
|
224
|
-
const code = value.charCodeAt(offset);
|
|
225
|
-
length += code === 39 || tcsh && (code === 33 || code === 9 || code === 11 || code === 12 || code === 13 || code === 32) ? 4 : tcsh && (code === 92 || code === 10) ? 2 : 1;
|
|
226
|
-
this.budget.room(length);
|
|
227
|
-
}
|
|
228
|
-
await this.publish(length, false, async (buffer) => {
|
|
229
|
-
let offset = 0;
|
|
230
|
-
buffer[offset++] = 32;
|
|
231
|
-
buffer[offset++] = 39;
|
|
232
|
-
for (let index = 0; index < value.length; index++) {
|
|
233
|
-
const code = value.charCodeAt(index);
|
|
234
|
-
await this.budget.step();
|
|
235
|
-
if (code === 39 || tcsh && (code === 33 || code === 9 || code === 11 || code === 12 || code === 13 || code === 32)) {
|
|
236
|
-
buffer[offset++] = 39;
|
|
237
|
-
buffer[offset++] = 92;
|
|
238
|
-
buffer[offset++] = code;
|
|
239
|
-
buffer[offset++] = 39;
|
|
240
|
-
} else if (tcsh && (code === 92 || code === 10)) {
|
|
241
|
-
buffer[offset++] = 92;
|
|
242
|
-
buffer[offset++] = code === 10 ? 110 : 92;
|
|
243
|
-
} else buffer[offset++] = code;
|
|
244
|
-
}
|
|
245
|
-
buffer[offset] = 39;
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// packages/safe-bash-command-getopt/src/parser.ts
|
|
251
|
-
init_platform();
|
|
252
|
-
async function findShort(specification, option, start, budget) {
|
|
253
|
-
for (let offset = start; offset < specification.length; offset++) {
|
|
254
|
-
await budget.step();
|
|
255
|
-
if (specification[offset] === option) return offset;
|
|
256
|
-
}
|
|
257
|
-
return -1;
|
|
258
|
-
}
|
|
259
|
-
async function addLongOptions(value, options, budget) {
|
|
260
|
-
budget.schema(value.length);
|
|
261
|
-
let start = 0;
|
|
262
|
-
for (let offset = 0; offset <= value.length; offset++) {
|
|
263
|
-
await budget.step();
|
|
264
|
-
const code = value.charCodeAt(offset);
|
|
265
|
-
if (offset !== value.length && code !== 44 && code !== 32 && code !== 9 && code !== 10) continue;
|
|
266
|
-
if (offset > start) {
|
|
267
|
-
let end = offset;
|
|
268
|
-
let argument = 0;
|
|
269
|
-
if (value[end - 1] === ":") {
|
|
270
|
-
argument = 1;
|
|
271
|
-
end--;
|
|
272
|
-
if (end > start && value[end - 1] === ":") {
|
|
273
|
-
argument = 2;
|
|
274
|
-
end--;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (end === start) throw new GetoptError("empty long option after -l or --long argument", 2, true);
|
|
278
|
-
budget.check(options.length + 1, budget.limits.maxLongOptions, "long option count");
|
|
279
|
-
budget.retain((end - start) * 2 + 64);
|
|
280
|
-
options.push({ name: value.slice(start, end), argument });
|
|
281
|
-
}
|
|
282
|
-
start = offset + 1;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
var Parser = class {
|
|
286
|
-
constructor(args, specification, options, alternative, posix, quiet, name, budget, writer) {
|
|
287
|
-
this.args = args;
|
|
288
|
-
this.specification = specification;
|
|
289
|
-
this.options = options;
|
|
290
|
-
this.alternative = alternative;
|
|
291
|
-
this.name = name;
|
|
292
|
-
this.budget = budget;
|
|
293
|
-
this.writer = writer;
|
|
294
|
-
this.start = specification[0] === "+" || specification[0] === "-" ? 1 : 0;
|
|
295
|
-
this.order = specification[0] === "-" ? "return" : specification[0] === "+" || posix ? "require" : "permute";
|
|
296
|
-
this.silent = quiet || specification[this.start] === ":";
|
|
297
|
-
}
|
|
298
|
-
args;
|
|
299
|
-
specification;
|
|
300
|
-
options;
|
|
301
|
-
alternative;
|
|
302
|
-
name;
|
|
303
|
-
budget;
|
|
304
|
-
writer;
|
|
305
|
-
index = 0;
|
|
306
|
-
offset = 0;
|
|
307
|
-
ended = false;
|
|
308
|
-
operands = [];
|
|
309
|
-
start;
|
|
310
|
-
order;
|
|
311
|
-
silent;
|
|
312
|
-
async error(parts) {
|
|
313
|
-
if (!this.silent) await this.writer.send([this.name, ...parts], true);
|
|
314
|
-
return { kind: "error" };
|
|
315
|
-
}
|
|
316
|
-
async long(value, prefix, fallback) {
|
|
317
|
-
let end = 0;
|
|
318
|
-
while (end < value.length && value[end] !== "=") {
|
|
319
|
-
await this.budget.step();
|
|
320
|
-
end++;
|
|
321
|
-
}
|
|
322
|
-
const lease = this.options.length * 64 + 128;
|
|
323
|
-
this.budget.retain(lease);
|
|
324
|
-
try {
|
|
325
|
-
const matches = [];
|
|
326
|
-
let exact;
|
|
327
|
-
for (const option2 of this.options) {
|
|
328
|
-
await this.budget.step();
|
|
329
|
-
let matched = option2.name.length >= end;
|
|
330
|
-
for (let offset = 0; matched && offset < end; offset++) {
|
|
331
|
-
await this.budget.step();
|
|
332
|
-
if (option2.name[offset] !== value[offset]) matched = false;
|
|
333
|
-
}
|
|
334
|
-
if (!matched) continue;
|
|
335
|
-
if (option2.name.length === end) {
|
|
336
|
-
exact = option2;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
matches.push(option2);
|
|
340
|
-
}
|
|
341
|
-
if (!exact && matches.length > 1) {
|
|
342
|
-
this.index++;
|
|
343
|
-
this.offset = 0;
|
|
344
|
-
if (!this.silent) {
|
|
345
|
-
const parts = [this.name, ": option '", prefix, value, "' is ambiguous; possibilities:"];
|
|
346
|
-
for (const option2 of matches) parts.push(" '", prefix, option2.name, "'");
|
|
347
|
-
parts.push("\n");
|
|
348
|
-
await this.writer.send(parts, true);
|
|
349
|
-
}
|
|
350
|
-
return { kind: "error" };
|
|
351
|
-
}
|
|
352
|
-
const option = exact ?? matches[0];
|
|
353
|
-
if (!option) {
|
|
354
|
-
if (fallback && await findShort(this.specification, value[0] ?? "", this.start, this.budget) >= 0) return null;
|
|
355
|
-
this.index++;
|
|
356
|
-
this.offset = 0;
|
|
357
|
-
return await this.error([": unrecognized option '", prefix, value, "'\n"]);
|
|
358
|
-
}
|
|
359
|
-
this.index++;
|
|
360
|
-
this.offset = 0;
|
|
361
|
-
let argument;
|
|
362
|
-
if (end < value.length) {
|
|
363
|
-
if (!option.argument) return await this.error([": option '", prefix, option.name, "' doesn't allow an argument\n"]);
|
|
364
|
-
argument = value.slice(end + 1);
|
|
365
|
-
} else if (option.argument === 1) {
|
|
366
|
-
if (this.index === this.args.length) return await this.error([": option '", prefix, option.name, "' requires an argument\n"]);
|
|
367
|
-
argument = this.args[this.index++];
|
|
368
|
-
}
|
|
369
|
-
return { kind: "long", option, argument };
|
|
370
|
-
} finally {
|
|
371
|
-
this.budget.retain(-lease);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
async next() {
|
|
375
|
-
await this.budget.step();
|
|
376
|
-
if (this.ended) return void 0;
|
|
377
|
-
if (!this.offset) {
|
|
378
|
-
while (this.index < this.args.length) {
|
|
379
|
-
await this.budget.step();
|
|
380
|
-
const argument3 = this.args[this.index];
|
|
381
|
-
if (argument3 === "--") {
|
|
382
|
-
this.index++;
|
|
383
|
-
this.ended = true;
|
|
384
|
-
return void 0;
|
|
385
|
-
}
|
|
386
|
-
if (argument3.length > 1 && argument3[0] === "-") break;
|
|
387
|
-
if (this.order === "require") {
|
|
388
|
-
this.ended = true;
|
|
389
|
-
return void 0;
|
|
390
|
-
}
|
|
391
|
-
this.index++;
|
|
392
|
-
if (this.order === "return") return { kind: "operand", argument: argument3 };
|
|
393
|
-
this.budget.retain(8);
|
|
394
|
-
this.operands.push(argument3);
|
|
395
|
-
}
|
|
396
|
-
if (this.index === this.args.length) {
|
|
397
|
-
this.ended = true;
|
|
398
|
-
return void 0;
|
|
399
|
-
}
|
|
400
|
-
const argument2 = this.args[this.index];
|
|
401
|
-
if (argument2[1] === "-") return await this.long(argument2.slice(2), "--", false);
|
|
402
|
-
if (this.alternative && (argument2.length > 2 || await findShort(this.specification, argument2[1], this.start, this.budget) < 0)) {
|
|
403
|
-
const result = await this.long(argument2.slice(1), "-", true);
|
|
404
|
-
if (result) return result;
|
|
405
|
-
}
|
|
406
|
-
this.offset = 1;
|
|
407
|
-
}
|
|
408
|
-
const current = this.args[this.index];
|
|
409
|
-
const option = current[this.offset++];
|
|
410
|
-
if (this.offset === current.length) {
|
|
411
|
-
this.offset = 0;
|
|
412
|
-
this.index++;
|
|
413
|
-
}
|
|
414
|
-
const found = await findShort(this.specification, option, this.start, this.budget);
|
|
415
|
-
if (found < 0 || option === ":" || option === ";") return this.error([": invalid option -- '", option, "'\n"]);
|
|
416
|
-
if (option === "W" && this.specification[found + 1] === ";") {
|
|
417
|
-
if (!this.offset && this.index === this.args.length) return this.error([": option requires an argument -- 'W'\n"]);
|
|
418
|
-
const value = this.offset ? current.slice(this.offset) : this.args[this.index];
|
|
419
|
-
return await this.long(value, "-W ", false);
|
|
420
|
-
}
|
|
421
|
-
let argument;
|
|
422
|
-
if (this.specification[found + 1] === ":") {
|
|
423
|
-
if (this.offset) {
|
|
424
|
-
argument = current.slice(this.offset);
|
|
425
|
-
this.index++;
|
|
426
|
-
} else if (this.specification[found + 2] !== ":") {
|
|
427
|
-
if (this.index === this.args.length) return this.error([": option requires an argument -- '", option, "'\n"]);
|
|
428
|
-
argument = this.args[this.index++];
|
|
429
|
-
}
|
|
430
|
-
this.offset = 0;
|
|
431
|
-
}
|
|
432
|
-
if (option === "?") return { kind: "error" };
|
|
433
|
-
if (option === "") return { kind: "operand", argument };
|
|
434
|
-
if (option === "\xFF") {
|
|
435
|
-
this.budget.retain(-this.operands.length * 8);
|
|
436
|
-
this.operands.length = 0;
|
|
437
|
-
this.ended = true;
|
|
438
|
-
return void 0;
|
|
439
|
-
}
|
|
440
|
-
return { kind: "short", option, argument };
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// packages/safe-bash-command-getopt/src/command.ts
|
|
445
|
-
var wrapperOptions = [
|
|
446
|
-
{ name: "options", argument: 1, code: "o" },
|
|
447
|
-
{ name: "longoptions", argument: 1, code: "l" },
|
|
448
|
-
{ name: "quiet", argument: 0, code: "q" },
|
|
449
|
-
{ name: "quiet-output", argument: 0, code: "Q" },
|
|
450
|
-
{ name: "shell", argument: 1, code: "s" },
|
|
451
|
-
{ name: "test", argument: 0, code: "T" },
|
|
452
|
-
{ name: "unquoted", argument: 0, code: "u" },
|
|
453
|
-
{ name: "help", argument: 0, code: "h" },
|
|
454
|
-
{ name: "alternative", argument: 0, code: "a" },
|
|
455
|
-
{ name: "name", argument: 1, code: "n" },
|
|
456
|
-
{ name: "version", argument: 0, code: "V" }
|
|
457
|
-
];
|
|
458
|
-
function createGetoptCommand(options = {}) {
|
|
459
|
-
const limits = settings(options);
|
|
460
|
-
return { name: "getopt", description: "Parse short and long options and emit shell-quoted arguments", async execute(context) {
|
|
461
|
-
const output = createOutputOperation(context, context.stdout);
|
|
462
|
-
const budget = new Budget(context, limits, output.signal);
|
|
463
|
-
let writer;
|
|
464
|
-
let failure;
|
|
465
|
-
let primary;
|
|
466
|
-
let exitCode = 0;
|
|
467
|
-
try {
|
|
468
|
-
writer = new Writer(budget, output);
|
|
469
|
-
const args = await budget.arguments();
|
|
470
|
-
const compatible = context.env.GETOPT_COMPATIBLE !== void 0;
|
|
471
|
-
const posix = context.env.POSIXLY_CORRECT !== void 0;
|
|
472
|
-
let specification;
|
|
473
|
-
let parameters = args;
|
|
474
|
-
const longOptions = [];
|
|
475
|
-
let quote = true, tcsh = false, quiet = false, quietOutput = false, alternative = false;
|
|
476
|
-
let name = "getopt";
|
|
477
|
-
let complete = false;
|
|
478
|
-
if (!args.length) {
|
|
479
|
-
if (!compatible) throw new GetoptError("missing optstring argument", 2, true);
|
|
480
|
-
await writer.send([" --\n"]);
|
|
481
|
-
complete = true;
|
|
482
|
-
} else if (compatible || args[0][0] !== "-") {
|
|
483
|
-
let start = 0;
|
|
484
|
-
while (args[0][start] === "+" || args[0][start] === "-") {
|
|
485
|
-
await budget.step();
|
|
486
|
-
start++;
|
|
487
|
-
}
|
|
488
|
-
specification = args[0].slice(start);
|
|
489
|
-
budget.schema(specification.length);
|
|
490
|
-
parameters = args.slice(1);
|
|
491
|
-
quote = false;
|
|
492
|
-
} else {
|
|
493
|
-
const wrapper = new Parser(args, "+ao:l:n:qQs:TuhV", wrapperOptions, false, posix, false, "getopt", budget, writer);
|
|
494
|
-
for (; ; ) {
|
|
495
|
-
const parsed = await wrapper.next();
|
|
496
|
-
if (!parsed) break;
|
|
497
|
-
if (parsed.kind === "error") {
|
|
498
|
-
await writer.send(["Try 'getopt --help' for more information.\n"], true);
|
|
499
|
-
exitCode = 2;
|
|
500
|
-
complete = true;
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
if (parsed.kind === "operand") throw new GetoptError("unexpected wrapper operand");
|
|
504
|
-
const option = parsed.kind === "long" ? parsed.option.code : parsed.option;
|
|
505
|
-
switch (option) {
|
|
506
|
-
case "o":
|
|
507
|
-
specification = parsed.argument;
|
|
508
|
-
budget.schema(specification.length);
|
|
509
|
-
break;
|
|
510
|
-
case "l":
|
|
511
|
-
await addLongOptions(parsed.argument, longOptions, budget);
|
|
512
|
-
break;
|
|
513
|
-
case "n":
|
|
514
|
-
name = parsed.argument;
|
|
515
|
-
break;
|
|
516
|
-
case "a":
|
|
517
|
-
alternative = true;
|
|
518
|
-
break;
|
|
519
|
-
case "q":
|
|
520
|
-
quiet = true;
|
|
521
|
-
break;
|
|
522
|
-
case "Q":
|
|
523
|
-
quietOutput = true;
|
|
524
|
-
break;
|
|
525
|
-
case "u":
|
|
526
|
-
quote = false;
|
|
527
|
-
break;
|
|
528
|
-
case "s":
|
|
529
|
-
if (parsed.argument === "bash" || parsed.argument === "sh") tcsh = false;
|
|
530
|
-
else if (parsed.argument === "tcsh" || parsed.argument === "csh") tcsh = true;
|
|
531
|
-
else throw new GetoptError("unknown shell after -s or --shell argument", 2, true);
|
|
532
|
-
break;
|
|
533
|
-
case "T":
|
|
534
|
-
exitCode = 4;
|
|
535
|
-
complete = true;
|
|
536
|
-
break;
|
|
537
|
-
case "V":
|
|
538
|
-
await writer.send(["getopt (virtual-bash)\n"]);
|
|
539
|
-
complete = true;
|
|
540
|
-
break;
|
|
541
|
-
case "h":
|
|
542
|
-
await writer.send(["Usage: getopt [OPTIONS] -o OPTSTRING [--] PARAMETERS...\nParse short and long options and emit shell-quoted arguments.\nOptions: -a, --alternative; -l, --longoptions; -n, --name; -o, --options;\n -q, --quiet; -Q, --quiet-output; -s, --shell; -T, --test;\n -u, --unquoted; -h, --help; -V, --version\n"]);
|
|
543
|
-
complete = true;
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
if (complete) break;
|
|
547
|
-
}
|
|
548
|
-
if (!complete) {
|
|
549
|
-
if (specification === void 0) {
|
|
550
|
-
if (wrapper.index === args.length) throw new GetoptError("missing optstring argument", 2, true);
|
|
551
|
-
specification = args[wrapper.index++];
|
|
552
|
-
budget.schema(specification.length);
|
|
553
|
-
}
|
|
554
|
-
parameters = args.slice(wrapper.index);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (!complete) {
|
|
558
|
-
const parser = new Parser(parameters, specification, longOptions, alternative, posix, quiet, name, budget, writer);
|
|
559
|
-
for (; ; ) {
|
|
560
|
-
const parsed = await parser.next();
|
|
561
|
-
if (!parsed) break;
|
|
562
|
-
if (parsed.kind === "error") {
|
|
563
|
-
exitCode = 1;
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
if (quietOutput) continue;
|
|
567
|
-
if (parsed.kind === "operand") await writer.normalized(parsed.argument ?? "", quote, tcsh);
|
|
568
|
-
else if (parsed.kind === "long") {
|
|
569
|
-
await writer.send([" --", parsed.option.name]);
|
|
570
|
-
if (parsed.option.argument) await writer.normalized(parsed.argument ?? "", quote, tcsh);
|
|
571
|
-
} else {
|
|
572
|
-
await writer.send([" -", parsed.option]);
|
|
573
|
-
const offset = await findShort(specification, parsed.option, 0, budget);
|
|
574
|
-
if (offset >= 0 && specification[offset + 1] === ":") await writer.normalized(parsed.argument ?? "", quote, tcsh);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (!quietOutput) {
|
|
578
|
-
await writer.send([" --"]);
|
|
579
|
-
for (const operand of parser.operands) await writer.normalized(operand, quote, tcsh);
|
|
580
|
-
for (let index = parser.index; index < parameters.length; index++) await writer.normalized(parameters[index], quote, tcsh);
|
|
581
|
-
await writer.send(["\n"]);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
} catch (error) {
|
|
585
|
-
primary = { reason: error };
|
|
586
|
-
if (error instanceof GetoptError && !output.signal.aborted && writer) {
|
|
587
|
-
exitCode = error.status;
|
|
588
|
-
try {
|
|
589
|
-
await writer.send(["getopt: ", error.message, "\n", error.usage ? "Try 'getopt --help' for more information.\n" : ""], true);
|
|
590
|
-
} catch (reporting) {
|
|
591
|
-
failure = { reason: new AggregateError([error, reporting], "getopt failure reporting failed") };
|
|
592
|
-
}
|
|
593
|
-
} else failure = { reason: error };
|
|
594
|
-
}
|
|
595
|
-
try {
|
|
596
|
-
await output.close();
|
|
597
|
-
} catch (cleanup) {
|
|
598
|
-
const previous = failure ?? primary;
|
|
599
|
-
failure = { reason: previous ? new AggregateError([previous.reason, cleanup], "getopt execution and cleanup failed") : cleanup };
|
|
600
|
-
}
|
|
601
|
-
context.signal.throwIfAborted();
|
|
602
|
-
output.signal.throwIfAborted();
|
|
603
|
-
if (failure) throw failure.reason;
|
|
604
|
-
return { exitCode };
|
|
605
|
-
} };
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// packages/safe-bash-command-getopt/src/index.ts
|
|
609
|
-
function createGetoptCommand2(options = {}) {
|
|
610
|
-
const def = createGetoptCommand(options);
|
|
611
|
-
if (options.limits === void 0) builtInDirectContextExecutors.add(def.execute);
|
|
612
|
-
return def;
|
|
613
|
-
}
|
|
614
|
-
function createGetoptCommands(options = {}) {
|
|
615
|
-
return [createGetoptCommand2(options)];
|
|
616
|
-
}
|
|
617
|
-
function getoptCommands(options = {}) {
|
|
618
|
-
const commands = createGetoptCommands(options);
|
|
619
|
-
return { name: "getopt-commands", setup(host) {
|
|
620
|
-
for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
|
|
621
|
-
} };
|
|
622
|
-
}
|
|
623
|
-
function quoteShell(value, quote, tcsh) {
|
|
624
|
-
if (!quote) return " " + value;
|
|
625
|
-
if (tcsh) {
|
|
626
|
-
return " '" + value.replace(/[\x27\n!]/g, (ch) => ch === "'" ? "'''" : "\\" + ch) + "'";
|
|
627
|
-
}
|
|
628
|
-
return " '" + value.replaceAll("'", "'\\''") + "'";
|
|
629
|
-
}
|
|
630
|
-
function evalSyncGetopt(args, env) {
|
|
631
|
-
if (args.length === 0 || args.length > 128) return void 0;
|
|
632
|
-
const compatible = env.GETOPT_COMPATIBLE !== void 0;
|
|
633
|
-
const posix = env.POSIXLY_CORRECT !== void 0;
|
|
634
|
-
let specification;
|
|
635
|
-
let parameters = args;
|
|
636
|
-
const longSpecs = /* @__PURE__ */ new Map();
|
|
637
|
-
let quote = true, tcsh = false, quietOutput = false, alternative = false;
|
|
638
|
-
if (compatible || !args[0].startsWith("-")) {
|
|
639
|
-
let start = 0;
|
|
640
|
-
while (args[0][start] === "+" || args[0][start] === "-") start++;
|
|
641
|
-
specification = args[0].slice(start);
|
|
642
|
-
parameters = args.slice(1);
|
|
643
|
-
quote = false;
|
|
644
|
-
} else {
|
|
645
|
-
let idx = 0;
|
|
646
|
-
const parseLongSpecList = (raw) => {
|
|
647
|
-
for (const token of raw.split(",")) {
|
|
648
|
-
if (!token) continue;
|
|
649
|
-
let name = token;
|
|
650
|
-
let argMode = 0;
|
|
651
|
-
if (name.endsWith("::")) {
|
|
652
|
-
argMode = 2;
|
|
653
|
-
name = name.slice(0, -2);
|
|
654
|
-
} else if (name.endsWith(":")) {
|
|
655
|
-
argMode = 1;
|
|
656
|
-
name = name.slice(0, -1);
|
|
657
|
-
}
|
|
658
|
-
if (!name) return false;
|
|
659
|
-
longSpecs.set(name, argMode);
|
|
660
|
-
}
|
|
661
|
-
return true;
|
|
662
|
-
};
|
|
663
|
-
while (idx < args.length) {
|
|
664
|
-
const a = args[idx];
|
|
665
|
-
if (a === "--") {
|
|
666
|
-
idx++;
|
|
667
|
-
break;
|
|
668
|
-
}
|
|
669
|
-
if (!a.startsWith("-") || a === "-") break;
|
|
670
|
-
if (a === "-o" || a === "--options") {
|
|
671
|
-
const v = args[++idx];
|
|
672
|
-
if (v === void 0) return void 0;
|
|
673
|
-
specification = v;
|
|
674
|
-
} else if (a.startsWith("--options=")) {
|
|
675
|
-
specification = a.slice(10);
|
|
676
|
-
} else if (a === "-l" || a === "--longoptions" || a === "--long") {
|
|
677
|
-
const v = args[++idx];
|
|
678
|
-
if (v === void 0 || !parseLongSpecList(v)) return void 0;
|
|
679
|
-
} else if (a.startsWith("--longoptions=")) {
|
|
680
|
-
if (!parseLongSpecList(a.slice(14))) return void 0;
|
|
681
|
-
} else if (a.startsWith("--long=")) {
|
|
682
|
-
if (!parseLongSpecList(a.slice(7))) return void 0;
|
|
683
|
-
} else if (a === "-q" || a === "--quiet") {
|
|
684
|
-
} else if (a === "-Q" || a === "--quiet-output") {
|
|
685
|
-
quietOutput = true;
|
|
686
|
-
} else if (a === "-u" || a === "--unquoted") {
|
|
687
|
-
quote = false;
|
|
688
|
-
} else if (a === "-a" || a === "--alternative") {
|
|
689
|
-
alternative = true;
|
|
690
|
-
} else if (a === "-n" || a === "--name") {
|
|
691
|
-
if (args[++idx] === void 0) return void 0;
|
|
692
|
-
} else if (a.startsWith("--name=")) {
|
|
693
|
-
} else if (a === "-s" || a === "--shell" || a.startsWith("--shell=")) {
|
|
694
|
-
const sh = a.startsWith("--shell=") ? a.slice(8) : args[++idx];
|
|
695
|
-
if (sh === "bash" || sh === "sh") tcsh = false;
|
|
696
|
-
else if (sh === "tcsh" || sh === "csh") tcsh = true;
|
|
697
|
-
else return void 0;
|
|
698
|
-
} else if (!a.startsWith("--") && a.length > 1) {
|
|
699
|
-
for (let j = 1; j < a.length; j++) {
|
|
700
|
-
const ch = a[j];
|
|
701
|
-
if (ch === "q") {
|
|
702
|
-
} else if (ch === "Q") quietOutput = true;
|
|
703
|
-
else if (ch === "u") quote = false;
|
|
704
|
-
else if (ch === "a") alternative = true;
|
|
705
|
-
else if (ch === "o") {
|
|
706
|
-
const rest = a.slice(j + 1);
|
|
707
|
-
const v = rest.length > 0 ? rest : args[++idx];
|
|
708
|
-
if (v === void 0) return void 0;
|
|
709
|
-
specification = v;
|
|
710
|
-
break;
|
|
711
|
-
} else if (ch === "l") {
|
|
712
|
-
const rest = a.slice(j + 1);
|
|
713
|
-
const v = rest.length > 0 ? rest : args[++idx];
|
|
714
|
-
if (v === void 0 || !parseLongSpecList(v)) return void 0;
|
|
715
|
-
break;
|
|
716
|
-
} else if (ch === "n") {
|
|
717
|
-
const rest = a.slice(j + 1);
|
|
718
|
-
const v = rest.length > 0 ? rest : args[++idx];
|
|
719
|
-
if (v === void 0) return void 0;
|
|
720
|
-
break;
|
|
721
|
-
} else if (ch === "s") {
|
|
722
|
-
const rest = a.slice(j + 1);
|
|
723
|
-
const sh = rest.length > 0 ? rest : args[++idx];
|
|
724
|
-
if (sh === "bash" || sh === "sh") tcsh = false;
|
|
725
|
-
else if (sh === "tcsh" || sh === "csh") tcsh = true;
|
|
726
|
-
else return void 0;
|
|
727
|
-
break;
|
|
728
|
-
} else {
|
|
729
|
-
return void 0;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
} else {
|
|
733
|
-
return void 0;
|
|
734
|
-
}
|
|
735
|
-
idx++;
|
|
736
|
-
}
|
|
737
|
-
if (specification === void 0) {
|
|
738
|
-
if (idx >= args.length) return void 0;
|
|
739
|
-
specification = args[idx++];
|
|
740
|
-
}
|
|
741
|
-
parameters = args.slice(idx);
|
|
742
|
-
}
|
|
743
|
-
let spec = specification;
|
|
744
|
-
let stopEarly = posix;
|
|
745
|
-
let returnInOrder = false;
|
|
746
|
-
if (spec.startsWith("+")) {
|
|
747
|
-
stopEarly = true;
|
|
748
|
-
spec = spec.slice(1);
|
|
749
|
-
} else if (spec.startsWith("-")) {
|
|
750
|
-
returnInOrder = true;
|
|
751
|
-
spec = spec.slice(1);
|
|
752
|
-
}
|
|
753
|
-
const shortMap = /* @__PURE__ */ new Map();
|
|
754
|
-
for (let i = 0; i < spec.length; i++) {
|
|
755
|
-
const ch = spec[i];
|
|
756
|
-
if (ch === ":") continue;
|
|
757
|
-
if (spec[i + 1] === ":" && spec[i + 2] === ":") {
|
|
758
|
-
shortMap.set(ch, 2);
|
|
759
|
-
i += 2;
|
|
760
|
-
} else if (spec[i + 1] === ":") {
|
|
761
|
-
shortMap.set(ch, 1);
|
|
762
|
-
i += 1;
|
|
763
|
-
} else shortMap.set(ch, 0);
|
|
764
|
-
}
|
|
765
|
-
let out = "";
|
|
766
|
-
const operands = [];
|
|
767
|
-
let pIdx = 0;
|
|
768
|
-
while (pIdx < parameters.length) {
|
|
769
|
-
const param = parameters[pIdx];
|
|
770
|
-
if (param === "--") {
|
|
771
|
-
pIdx++;
|
|
772
|
-
while (pIdx < parameters.length) operands.push(parameters[pIdx++]);
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
if (!param.startsWith("-") || param === "-") {
|
|
776
|
-
if (stopEarly) {
|
|
777
|
-
while (pIdx < parameters.length) operands.push(parameters[pIdx++]);
|
|
778
|
-
break;
|
|
779
|
-
}
|
|
780
|
-
if (returnInOrder) out += quoteShell(param, quote, tcsh);
|
|
781
|
-
else operands.push(param);
|
|
782
|
-
pIdx++;
|
|
783
|
-
continue;
|
|
784
|
-
}
|
|
785
|
-
if (param.startsWith("--") || alternative && param.startsWith("-") && longSpecs.size > 0 && !shortMap.has(param[1])) {
|
|
786
|
-
const rawLong = param.startsWith("--") ? param.slice(2) : param.slice(1);
|
|
787
|
-
const eq = rawLong.indexOf("=");
|
|
788
|
-
const optName = eq < 0 ? rawLong : rawLong.slice(0, eq);
|
|
789
|
-
const inlineVal = eq < 0 ? void 0 : rawLong.slice(eq + 1);
|
|
790
|
-
let matchedName;
|
|
791
|
-
if (longSpecs.has(optName)) {
|
|
792
|
-
matchedName = optName;
|
|
793
|
-
} else {
|
|
794
|
-
const matches = [...longSpecs.keys()].filter((k) => k.startsWith(optName));
|
|
795
|
-
if (matches.length !== 1) return void 0;
|
|
796
|
-
matchedName = matches[0];
|
|
797
|
-
}
|
|
798
|
-
const mode = longSpecs.get(matchedName);
|
|
799
|
-
out += ` --${matchedName}`;
|
|
800
|
-
if (mode === 0) {
|
|
801
|
-
if (inlineVal !== void 0) return void 0;
|
|
802
|
-
} else if (mode === 1) {
|
|
803
|
-
const val = inlineVal ?? parameters[++pIdx];
|
|
804
|
-
if (val === void 0) return void 0;
|
|
805
|
-
out += quoteShell(val, quote, tcsh);
|
|
806
|
-
} else {
|
|
807
|
-
out += quoteShell(inlineVal ?? "", quote, tcsh);
|
|
808
|
-
}
|
|
809
|
-
pIdx++;
|
|
810
|
-
continue;
|
|
811
|
-
}
|
|
812
|
-
for (let j = 1; j < param.length; j++) {
|
|
813
|
-
const ch = param[j];
|
|
814
|
-
const mode = shortMap.get(ch);
|
|
815
|
-
if (mode === void 0) return void 0;
|
|
816
|
-
out += ` -${ch}`;
|
|
817
|
-
if (mode === 1) {
|
|
818
|
-
const rest = param.slice(j + 1);
|
|
819
|
-
const val = rest.length > 0 ? rest : parameters[++pIdx];
|
|
820
|
-
if (val === void 0) return void 0;
|
|
821
|
-
out += quoteShell(val, quote, tcsh);
|
|
822
|
-
break;
|
|
823
|
-
} else if (mode === 2) {
|
|
824
|
-
const rest = param.slice(j + 1);
|
|
825
|
-
out += quoteShell(rest, quote, tcsh);
|
|
826
|
-
break;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
pIdx++;
|
|
830
|
-
}
|
|
831
|
-
if (quietOutput) return "";
|
|
832
|
-
out += " --";
|
|
833
|
-
for (const op of operands) out += quoteShell(op, quote, tcsh);
|
|
834
|
-
return out;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
export {
|
|
838
|
-
createGetoptCommand2 as createGetoptCommand,
|
|
839
|
-
createGetoptCommands,
|
|
840
|
-
getoptCommands,
|
|
841
|
-
evalSyncGetopt
|
|
842
|
-
};
|
|
843
|
-
//# sourceMappingURL=chunk-WPUALYUS.js.map
|