@poe-platform/safe-bash 0.1.630 → 0.1.632
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/office-package/compression.d.ts +19 -0
- package/dist/office-package/compression.js +186 -0
- package/dist/office-package/runtime.d.ts +11 -0
- package/dist/office-package/runtime.js +28 -0
- package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js → bz2-ACU4EOVE.js} +2 -2
- package/dist/safe-bash/chunks/chunk-2E4KBFO6.js +239 -0
- package/dist/safe-bash/chunks/chunk-2E4KBFO6.js.map +7 -0
- package/dist/safe-bash/chunks/chunk-3E5M2WEL.js +33 -0
- package/dist/safe-bash/chunks/chunk-3E5M2WEL.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-KQ6J7JHQ.js → chunk-3LD67SER.js} +12 -10
- package/dist/safe-bash/chunks/{chunk-KQ6J7JHQ.js.map → chunk-3LD67SER.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js → chunk-6HNK7Q66.js} +11 -7
- package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js.map → chunk-6HNK7Q66.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js → chunk-7EEWZY5S.js} +10 -8
- package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js.map → chunk-7EEWZY5S.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js → chunk-CDBQXRWL.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-UYX72YHY.js → chunk-CHHAB5SS.js} +10 -74
- package/dist/safe-bash/chunks/{chunk-UYX72YHY.js.map → chunk-CHHAB5SS.js.map} +3 -3
- package/dist/safe-bash/chunks/{chunk-6YSBXTTJ.js → chunk-EI4X5ETX.js} +12 -10
- package/dist/safe-bash/chunks/{chunk-6YSBXTTJ.js.map → chunk-EI4X5ETX.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js → chunk-GIBLUW2U.js} +13 -9
- package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js.map → chunk-GIBLUW2U.js.map} +1 -1
- package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js +1528 -0
- package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js → chunk-H3E67KTZ.js} +13 -9
- package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js.map → chunk-H3E67KTZ.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-AFH57PPL.js → chunk-IEKESMO4.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js → chunk-JLBIUYT3.js} +2 -2
- package/dist/safe-bash/chunks/chunk-JZDO5MC3.js +77 -0
- package/dist/safe-bash/chunks/chunk-JZDO5MC3.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js → chunk-LA6BX562.js} +8 -6
- package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js.map → chunk-LA6BX562.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js → chunk-M3GPCYSP.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js → chunk-NDCZ3UBP.js} +13 -9
- package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js.map → chunk-NDCZ3UBP.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js → chunk-O2EVBRKF.js} +1 -2
- package/dist/safe-bash/chunks/chunk-OFT77XIB.js +389 -0
- package/dist/safe-bash/chunks/chunk-OFT77XIB.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-PCLOK32J.js → chunk-PC6BEIAF.js} +13 -9
- package/dist/safe-bash/chunks/{chunk-PCLOK32J.js.map → chunk-PC6BEIAF.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js → chunk-QWKP7ZU7.js} +13 -9
- package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js.map → chunk-QWKP7ZU7.js.map} +1 -1
- package/dist/safe-bash/chunks/chunk-THXJ6CLF.js +53 -0
- package/dist/safe-bash/chunks/chunk-THXJ6CLF.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-K7W6Q6FN.js → chunk-V73A742N.js} +58 -16
- package/dist/safe-bash/chunks/chunk-V73A742N.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js → chunk-VN3ZGME3.js} +12 -8
- package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js.map → chunk-VN3ZGME3.js.map} +1 -1
- package/dist/safe-bash/chunks/{chunk-3BZ5NQ73.js → chunk-WECHUK3Y.js} +369 -36
- package/dist/safe-bash/chunks/chunk-WECHUK3Y.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-X55AMTNM.js → chunk-WIOEUR7D.js} +14 -10
- package/dist/safe-bash/chunks/{chunk-X55AMTNM.js.map → chunk-WIOEUR7D.js.map} +1 -1
- package/dist/safe-bash/chunks/chunk-WPIOO4NX.js +443 -0
- package/dist/safe-bash/chunks/chunk-WPIOO4NX.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js → chunk-WYTI64IU.js} +2 -2
- package/dist/safe-bash/chunks/{xz-AVXFDXW4.js → xz-U4QDTPZL.js} +2 -2
- package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js → zstd-OG5RPYXO.js} +2 -2
- package/dist/safe-bash/commands/archive/zip/crc.d.ts +2 -0
- package/dist/safe-bash/commands/archive/zip/crc.d.ts.map +1 -0
- package/dist/safe-bash/commands/archive/zip/crc.js +7 -0
- package/dist/safe-bash/commands/archive/zip/crc.js.map +1 -0
- package/dist/safe-bash/commands/archive/zip/crypto.d.ts +4 -0
- package/dist/safe-bash/commands/archive/zip/crypto.d.ts.map +1 -0
- package/dist/safe-bash/commands/archive/zip/crypto.js +34 -0
- package/dist/safe-bash/commands/archive/zip/crypto.js.map +1 -0
- package/dist/safe-bash/commands/archive/zip/help.d.ts +3 -0
- package/dist/safe-bash/commands/archive/zip/help.d.ts.map +1 -0
- package/dist/safe-bash/commands/archive/zip/help.js +87 -0
- package/dist/safe-bash/commands/archive/zip/help.js.map +1 -0
- package/dist/safe-bash/commands/archive/zip/move.d.ts +12 -0
- package/dist/safe-bash/commands/archive/zip/move.d.ts.map +1 -0
- package/dist/safe-bash/commands/archive/zip/move.js +60 -0
- package/dist/safe-bash/commands/archive/zip/move.js.map +1 -0
- package/dist/safe-bash/commands/archive/zip/options.js +5 -5
- package/dist/safe-bash/commands/archive/zip/options.js.map +1 -1
- package/dist/safe-bash/commands/archive/zip-format.d.ts +1 -1
- package/dist/safe-bash/commands/archive/zip-format.d.ts.map +1 -1
- package/dist/safe-bash/commands/archive/zip-format.js +14 -17
- package/dist/safe-bash/commands/archive/zip-format.js.map +1 -1
- package/dist/safe-bash/commands/archive/zip.d.ts.map +1 -1
- package/dist/safe-bash/commands/archive/zip.js +45 -15
- package/dist/safe-bash/commands/archive/zip.js.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts +2 -0
- package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/bounded-codec.js +4 -0
- package/dist/safe-bash/commands/bytes/compression/bounded-codec.js.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/codec.d.ts +4 -24
- package/dist/safe-bash/commands/bytes/compression/codec.d.ts.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/codec.js +12 -168
- package/dist/safe-bash/commands/bytes/compression/codec.js.map +1 -1
- package/dist/safe-bash/commands/cmp.js +1 -1
- package/dist/safe-bash/commands/cmp.js.map +1 -1
- package/dist/safe-bash/commands/csplit/index.browser.js +10 -7
- package/dist/safe-bash/commands/docx/index.browser.js +54 -0
- package/dist/safe-bash/commands/docx/index.browser.js.map +7 -0
- package/dist/safe-bash/commands/docx/index.d.ts +25 -0
- package/dist/safe-bash/commands/docx/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/docx/index.js +42 -0
- package/dist/safe-bash/commands/docx/index.js.map +1 -0
- package/dist/safe-bash/commands/docx/io.d.ts +15 -0
- package/dist/safe-bash/commands/docx/io.d.ts.map +1 -0
- package/dist/safe-bash/commands/docx/io.js +16 -0
- package/dist/safe-bash/commands/docx/io.js.map +1 -0
- package/dist/safe-bash/commands/factor/index.browser.js +7 -5
- package/dist/safe-bash/commands/filesystem.d.ts.map +1 -1
- package/dist/safe-bash/commands/filesystem.js +9 -1
- package/dist/safe-bash/commands/filesystem.js.map +1 -1
- package/dist/safe-bash/commands/getopt/index.browser.js +7 -5
- package/dist/safe-bash/commands/hexdump/index.browser.js +8 -6
- package/dist/safe-bash/commands/iconv/index.browser.js +8 -6
- package/dist/safe-bash/commands/line-endings/index.browser.js +10 -7
- package/dist/safe-bash/commands/llm/index.browser.js +10 -8
- package/dist/safe-bash/commands/llm/providers/index.browser.js +3 -3
- package/dist/safe-bash/commands/network/index.browser.js +11 -8
- package/dist/safe-bash/commands/node/index.browser.js +8 -6
- package/dist/safe-bash/commands/op/index.browser.js +3 -3
- package/dist/safe-bash/commands/op/index.js +0 -1
- package/dist/safe-bash/commands/op/index.js.map +2 -2
- package/dist/safe-bash/commands/pptx/index.d.ts +29 -0
- package/dist/safe-bash/commands/pptx/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/pptx/index.js +153 -0
- package/dist/safe-bash/commands/pptx/index.js.map +1 -0
- package/dist/safe-bash/commands/pr/index.browser.js +8 -6
- package/dist/safe-bash/commands/predicates.js +1 -1
- package/dist/safe-bash/commands/python/execution.d.ts +3 -0
- package/dist/safe-bash/commands/python/execution.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/execution.js +193 -0
- package/dist/safe-bash/commands/python/execution.js.map +1 -0
- package/dist/safe-bash/commands/python/index.browser.js +21 -0
- package/dist/safe-bash/commands/python/index.browser.js.map +7 -0
- package/dist/safe-bash/commands/python/index.d.ts +49 -0
- package/dist/safe-bash/commands/python/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/index.js +317 -0
- package/dist/safe-bash/commands/python/index.js.map +1 -0
- package/dist/safe-bash/commands/python/installation.d.ts +9 -0
- package/dist/safe-bash/commands/python/installation.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/installation.js +80 -0
- package/dist/safe-bash/commands/python/installation.js.map +1 -0
- package/dist/safe-bash/commands/python/invocation.d.ts +10 -0
- package/dist/safe-bash/commands/python/invocation.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/invocation.js +81 -0
- package/dist/safe-bash/commands/python/invocation.js.map +1 -0
- package/dist/safe-bash/commands/python/node.d.ts +12 -0
- package/dist/safe-bash/commands/python/node.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/node.js +33 -0
- package/dist/safe-bash/commands/python/node.js.map +1 -0
- package/dist/safe-bash/commands/python/provisioning-runtime.d.ts +5 -0
- package/dist/safe-bash/commands/python/provisioning-runtime.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/provisioning-runtime.js +179 -0
- package/dist/safe-bash/commands/python/provisioning-runtime.js.map +1 -0
- package/dist/safe-bash/commands/python/provisioning.d.ts +49 -0
- package/dist/safe-bash/commands/python/provisioning.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/provisioning.js +320 -0
- package/dist/safe-bash/commands/python/provisioning.js.map +1 -0
- package/dist/safe-bash/commands/python/reply.d.ts +3 -0
- package/dist/safe-bash/commands/python/reply.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/reply.js +103 -0
- package/dist/safe-bash/commands/python/reply.js.map +1 -0
- package/dist/safe-bash/commands/python/worker.browser.js +736 -0
- package/dist/safe-bash/commands/python/worker.browser.js.map +7 -0
- package/dist/safe-bash/commands/python/worker.d.ts +47 -0
- package/dist/safe-bash/commands/python/worker.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/worker.js +373 -0
- package/dist/safe-bash/commands/python/worker.js.map +1 -0
- package/dist/safe-bash/commands/tsort/index.browser.js +8 -6
- package/dist/safe-bash/commands/xml/index.browser.js +9 -7
- package/dist/safe-bash/commands/yq/index.browser.js +10 -8
- package/dist/safe-bash/commands/yq/index.d.ts.map +1 -1
- package/dist/safe-bash/commands/yq/index.js +32 -4
- package/dist/safe-bash/commands/yq/index.js.map +1 -1
- package/dist/safe-bash/commands/yq/parser.d.ts.map +1 -1
- package/dist/safe-bash/commands/yq/parser.js +21 -5
- package/dist/safe-bash/commands/yq/parser.js.map +1 -1
- package/dist/safe-bash/contracts/command.d.ts +2 -0
- package/dist/safe-bash/contracts/command.d.ts.map +1 -1
- package/dist/safe-bash/contracts/command.js +6 -2
- package/dist/safe-bash/contracts/command.js.map +1 -1
- package/dist/safe-bash/contracts/filesystem-descriptor.d.ts +13 -0
- package/dist/safe-bash/contracts/filesystem-descriptor.d.ts.map +1 -0
- package/dist/safe-bash/contracts/filesystem-descriptor.js +189 -0
- package/dist/safe-bash/contracts/filesystem-descriptor.js.map +1 -0
- package/dist/safe-bash/contracts/filesystem-output-budget.d.ts +15 -0
- package/dist/safe-bash/contracts/filesystem-output-budget.d.ts.map +1 -0
- package/dist/safe-bash/contracts/filesystem-output-budget.js +69 -0
- package/dist/safe-bash/contracts/filesystem-output-budget.js.map +1 -0
- package/dist/safe-bash/contracts/filesystem-output.d.ts +11 -5
- package/dist/safe-bash/contracts/filesystem-output.d.ts.map +1 -1
- package/dist/safe-bash/contracts/filesystem-output.js +229 -20
- package/dist/safe-bash/contracts/filesystem-output.js.map +1 -1
- package/dist/safe-bash/contracts/io.d.ts +29 -0
- package/dist/safe-bash/contracts/io.d.ts.map +1 -1
- package/dist/safe-bash/contracts/io.js +317 -37
- package/dist/safe-bash/contracts/io.js.map +1 -1
- package/dist/safe-bash/core.browser.js +5502 -2210
- package/dist/safe-bash/core.browser.js.map +4 -4
- package/dist/safe-bash/core.d.ts +1 -0
- package/dist/safe-bash/core.d.ts.map +1 -1
- package/dist/safe-bash/core.js +1 -0
- package/dist/safe-bash/core.js.map +1 -1
- package/dist/safe-bash/opt-in/commands/cmp/compare.js +95 -0
- package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -0
- package/dist/safe-bash/opt-in/commands/cmp/index.js +99 -0
- package/dist/safe-bash/opt-in/commands/cmp/io.js +218 -0
- package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +24 -0
- package/dist/safe-bash/opt-in/commands/cmp/options.js +195 -0
- package/dist/safe-bash/opt-in/commands/dd/conversions.js +152 -0
- package/dist/safe-bash/opt-in/commands/dd/index.d.ts +18 -0
- package/dist/safe-bash/opt-in/commands/dd/index.js +561 -0
- package/dist/safe-bash/opt-in/commands/dd/io.d.ts +31 -0
- package/dist/safe-bash/opt-in/commands/dd/io.js +244 -0
- package/dist/safe-bash/opt-in/commands/dd/options.js +184 -0
- package/dist/safe-bash/opt-in/commands/dd/report.js +69 -0
- package/dist/safe-bash/opt-in/commands/install/arguments.js +224 -0
- package/dist/safe-bash/opt-in/commands/install/index.d.ts +6 -0
- package/dist/safe-bash/opt-in/commands/install/index.js +678 -0
- package/dist/safe-bash/opt-in/commands/install/mode.js +71 -0
- package/dist/safe-bash/opt-in/commands/install/options.d.ts +36 -0
- package/dist/safe-bash/opt-in/commands/install/options.js +27 -0
- package/dist/safe-bash/opt-in/commands/shuf/args.js +179 -0
- package/dist/safe-bash/opt-in/commands/shuf/index.d.ts +6 -0
- package/dist/safe-bash/opt-in/commands/shuf/index.js +20 -0
- package/dist/safe-bash/opt-in/commands/shuf/input.js +93 -0
- package/dist/safe-bash/opt-in/commands/shuf/options.d.ts +9 -0
- package/dist/safe-bash/opt-in/commands/shuf/options.js +8 -0
- package/dist/safe-bash/opt-in/commands/shuf/random.js +114 -0
- package/dist/safe-bash/opt-in/commands/shuf/shuf.d.ts +3 -0
- package/dist/safe-bash/opt-in/commands/shuf/shuf.js +230 -0
- package/dist/safe-bash/opt-in/commands/shuf/usage.js +24 -0
- package/dist/safe-bash/opt-in/commands/truncate/arguments.js +186 -0
- package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +9 -0
- package/dist/safe-bash/opt-in/commands/truncate/index.js +244 -0
- package/dist/safe-bash/opt-in/commands/yes/index.d.ts +11 -0
- package/dist/safe-bash/opt-in/commands/yes/index.js +167 -0
- package/dist/safe-bash/opt-in/commands/yq/arguments.js +177 -0
- package/dist/safe-bash/opt-in/commands/yq/evaluate.js +564 -0
- package/dist/safe-bash/opt-in/commands/yq/expression.js +183 -0
- package/dist/safe-bash/opt-in/commands/yq/inplace.js +65 -0
- package/dist/safe-bash/opt-in/commands/yq/mike.d.ts +9 -0
- package/dist/safe-bash/opt-in/commands/yq/mike.js +192 -0
- package/dist/safe-bash/opt-in/commands/yq/native-encoder.js +165 -0
- package/dist/safe-bash/opt-in/commands/yq/native-work.d.ts +44 -0
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +188 -0
- package/dist/safe-bash/opt-in/commands/yq/nodes.js +621 -0
- package/dist/safe-bash/opt-in/entrypoints/arrays.d.ts +1 -0
- package/dist/safe-bash/opt-in/entrypoints/arrays.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/cmp.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/cmp.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/dd.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/dd.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/devices.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/devices.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/install.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/install.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/jobs.d.ts +1 -0
- package/dist/safe-bash/opt-in/entrypoints/jobs.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/mapfile.d.ts +1 -0
- package/dist/safe-bash/opt-in/entrypoints/mapfile.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/read.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/read.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/shuf.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/shuf.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/trap.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/trap.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/truncate.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/truncate.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/yes.d.ts +2 -0
- package/dist/safe-bash/opt-in/entrypoints/yes.js +1 -0
- package/dist/safe-bash/opt-in/entrypoints/yq.d.ts +3 -0
- package/dist/safe-bash/opt-in/entrypoints/yq.js +1 -0
- package/dist/safe-bash/opt-in/fs/devices/index.d.ts +8 -0
- package/dist/safe-bash/opt-in/fs/devices/index.js +292 -0
- package/dist/safe-bash/opt-in/optional.d.ts +28 -0
- package/dist/safe-bash/opt-in/optional.js +14 -0
- package/dist/safe-bash/opt-in/shell/extensions/arrays/index.d.ts +2 -0
- package/dist/safe-bash/opt-in/shell/extensions/arrays/index.js +4 -0
- package/dist/safe-bash/opt-in/shell/extensions/jobs/index.d.ts +2 -0
- package/dist/safe-bash/opt-in/shell/extensions/jobs/index.js +291 -0
- package/dist/safe-bash/opt-in/shell/extensions/jobs/state.js +374 -0
- package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.d.ts +24 -0
- package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.js +338 -0
- package/dist/safe-bash/opt-in/shell/extensions/read/index.d.ts +5 -0
- package/dist/safe-bash/opt-in/shell/extensions/read/index.js +351 -0
- package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +9 -0
- package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +210 -0
- package/dist/safe-bash/optional-host.d.ts +5 -0
- package/dist/safe-bash/optional-host.d.ts.map +1 -0
- package/dist/safe-bash/optional-host.js +3 -0
- package/dist/safe-bash/optional-host.js.map +1 -0
- package/dist/safe-bash/shell/arrays/bindings.d.ts +15 -5
- package/dist/safe-bash/shell/arrays/bindings.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/bindings.js +131 -23
- package/dist/safe-bash/shell/arrays/bindings.js.map +1 -1
- package/dist/safe-bash/shell/arrays/ledger.d.ts +1 -0
- package/dist/safe-bash/shell/arrays/ledger.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/ledger.js +19 -0
- package/dist/safe-bash/shell/arrays/ledger.js.map +1 -1
- package/dist/safe-bash/shell/arrays/state.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/state.js +3 -1
- package/dist/safe-bash/shell/arrays/state.js.map +1 -1
- package/dist/safe-bash/shell/arrays/syntax.d.ts +4 -1
- package/dist/safe-bash/shell/arrays/syntax.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/syntax.js +3 -3
- package/dist/safe-bash/shell/arrays/syntax.js.map +1 -1
- package/dist/safe-bash/shell/conditional.js +1 -1
- package/dist/safe-bash/shell/descriptors.d.ts +31 -0
- package/dist/safe-bash/shell/descriptors.d.ts.map +1 -0
- package/dist/safe-bash/shell/descriptors.js +234 -0
- package/dist/safe-bash/shell/descriptors.js.map +1 -0
- package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts +2 -0
- package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts.map +1 -0
- package/dist/safe-bash/shell/diagnostic-name-ranges.js +717 -0
- package/dist/safe-bash/shell/diagnostic-name-ranges.js.map +1 -0
- package/dist/safe-bash/shell/diagnostic-name.d.ts +3 -0
- package/dist/safe-bash/shell/diagnostic-name.d.ts.map +1 -0
- package/dist/safe-bash/shell/diagnostic-name.js +89 -0
- package/dist/safe-bash/shell/diagnostic-name.js.map +1 -0
- package/dist/safe-bash/shell/display.js +1 -1
- package/dist/safe-bash/shell/display.js.map +1 -1
- package/dist/safe-bash/shell/extensions.d.ts +188 -0
- package/dist/safe-bash/shell/extensions.d.ts.map +1 -0
- package/dist/safe-bash/shell/extensions.js +141 -0
- package/dist/safe-bash/shell/extensions.js.map +1 -0
- package/dist/safe-bash/shell/input.d.ts +66 -14
- package/dist/safe-bash/shell/input.d.ts.map +1 -1
- package/dist/safe-bash/shell/input.js +947 -173
- package/dist/safe-bash/shell/input.js.map +1 -1
- package/dist/safe-bash/shell/parser.d.ts +38 -6
- package/dist/safe-bash/shell/parser.d.ts.map +1 -1
- package/dist/safe-bash/shell/parser.js +339 -52
- package/dist/safe-bash/shell/parser.js.map +1 -1
- package/dist/safe-bash/shell/runtime.d.ts +92 -20
- package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
- package/dist/safe-bash/shell/runtime.js +2547 -689
- package/dist/safe-bash/shell/runtime.js.map +1 -1
- package/dist/safe-bash/shell/shell.d.ts.map +1 -1
- package/dist/safe-bash/shell/shell.js +52 -21
- package/dist/safe-bash/shell/shell.js.map +1 -1
- package/dist/safe-bash/shell/types.d.ts +4 -0
- package/dist/safe-bash/shell/types.d.ts.map +1 -1
- package/dist/safe-bash/shell/types.js.map +1 -1
- package/package.json +92 -4
- package/dist/safe-bash/chunks/chunk-3BZ5NQ73.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-4DBWBEU7.js +0 -194
- package/dist/safe-bash/chunks/chunk-4DBWBEU7.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-CXMIIXJA.js +0 -178
- package/dist/safe-bash/chunks/chunk-CXMIIXJA.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-K7W6Q6FN.js.map +0 -7
- /package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js.map → bz2-ACU4EOVE.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js.map → chunk-CDBQXRWL.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-AFH57PPL.js.map → chunk-IEKESMO4.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js.map → chunk-JLBIUYT3.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js.map → chunk-M3GPCYSP.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js.map → chunk-O2EVBRKF.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js.map → chunk-WYTI64IU.js.map} +0 -0
- /package/dist/safe-bash/chunks/{xz-AVXFDXW4.js.map → xz-U4QDTPZL.js.map} +0 -0
- /package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js.map → zstd-OG5RPYXO.js.map} +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { commandRuntimeIdentity, FsError, dirname, getCommandArguments, writeBytes } from "@poe-platform/safe-bash/contracts/index";
|
|
2
|
+
import { codeOf, pathOf } from "@poe-platform/safe-bash/optional-host";
|
|
3
|
+
import { yieldTurn } from "@poe-platform/safe-bash/contracts/yield";
|
|
4
|
+
import { argumentBytes, helpText, maximumSize, minimumSize, parseArguments, quote, TruncateError } from "./arguments.js";
|
|
5
|
+
function operandPath(context, operand) {
|
|
6
|
+
let name;
|
|
7
|
+
try {
|
|
8
|
+
name = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(argumentBytes(operand));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new FsError("ENOTSUP");
|
|
12
|
+
}
|
|
13
|
+
return pathOf(context, name);
|
|
14
|
+
}
|
|
15
|
+
const errors = {
|
|
16
|
+
EACCES: "Permission denied", EPERM: "Operation not permitted", ENOENT: "No such file or directory",
|
|
17
|
+
EISDIR: "Is a directory", ENOTDIR: "Not a directory", ELOOP: "Too many levels of symbolic links",
|
|
18
|
+
EROFS: "Read-only file system", ENOSPC: "No space left on device", EFBIG: "File too large",
|
|
19
|
+
EINVAL: "Invalid argument", EIO: "Input/output error", ENAMETOOLONG: "File name too long",
|
|
20
|
+
ENOTSUP: "Operation not supported", EOPNOTSUPP: "Operation not supported", ENOSYS: "Function not implemented",
|
|
21
|
+
};
|
|
22
|
+
function failure(operation, error) {
|
|
23
|
+
const code = codeOf(error);
|
|
24
|
+
return new TruncateError(`${operation}: ${code && errors[code] || (error instanceof Error ? error.message : String(error))}`);
|
|
25
|
+
}
|
|
26
|
+
async function measuredSize(context, path, stat, operand, options) {
|
|
27
|
+
let size = stat.size;
|
|
28
|
+
if (stat.type !== "file" && stat.type !== "symlink") {
|
|
29
|
+
if (!options.seekEnd)
|
|
30
|
+
throw new TruncateError(`cannot get the size of ${quote(operand)}: Operation not supported (seek-end measurement is unavailable)`);
|
|
31
|
+
try {
|
|
32
|
+
context.signal.throwIfAborted();
|
|
33
|
+
size = await options.seekEnd(path, stat, context);
|
|
34
|
+
context.signal.throwIfAborted();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw failure(`cannot get the size of ${quote(operand)}`, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isSafeInteger(size) || size < 0)
|
|
41
|
+
throw new TruncateError(`${quote(operand)} has unusable size: Operation not supported`);
|
|
42
|
+
return BigInt(size);
|
|
43
|
+
}
|
|
44
|
+
async function admit(context, path, create) {
|
|
45
|
+
const check = (capabilities) => {
|
|
46
|
+
if (capabilities.readOnly)
|
|
47
|
+
throw new FsError("EROFS");
|
|
48
|
+
if (capabilities.truncate === false || !context.fs.truncate || capabilities.stat === false
|
|
49
|
+
|| (create && capabilities.append === false))
|
|
50
|
+
throw new FsError("ENOTSUP");
|
|
51
|
+
};
|
|
52
|
+
check(context.fs.capabilities);
|
|
53
|
+
if (!context.fs.capabilitiesFor)
|
|
54
|
+
return;
|
|
55
|
+
let candidate = path;
|
|
56
|
+
while (true) {
|
|
57
|
+
context.signal.throwIfAborted();
|
|
58
|
+
try {
|
|
59
|
+
const capabilities = await context.fs.capabilitiesFor(candidate, { signal: context.signal });
|
|
60
|
+
context.signal.throwIfAborted();
|
|
61
|
+
check(capabilities);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (codeOf(error) !== "ENOENT" || candidate === "/")
|
|
66
|
+
throw error;
|
|
67
|
+
candidate = dirname(candidate);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function truncateFile(context, args, operand, reference, options) {
|
|
72
|
+
let stat, path;
|
|
73
|
+
const fsOptions = { signal: context.signal };
|
|
74
|
+
try {
|
|
75
|
+
if (operand === "" && args.noCreate)
|
|
76
|
+
return;
|
|
77
|
+
path = operandPath(context, operand);
|
|
78
|
+
let existing;
|
|
79
|
+
try {
|
|
80
|
+
existing = await context.fs.stat(path, fsOptions);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (codeOf(error) !== "ENOENT")
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
context.signal.throwIfAborted();
|
|
87
|
+
if (existing === undefined && args.noCreate)
|
|
88
|
+
return;
|
|
89
|
+
if (existing?.type === "directory")
|
|
90
|
+
throw new FsError("EISDIR");
|
|
91
|
+
await admit(context, path, existing === undefined);
|
|
92
|
+
context.signal.throwIfAborted();
|
|
93
|
+
if (existing === undefined) {
|
|
94
|
+
await context.fs.writeFile(path, new Uint8Array(), { ...fsOptions, flag: "a", mode: 0o666 });
|
|
95
|
+
context.signal.throwIfAborted();
|
|
96
|
+
existing = await context.fs.stat(path, fsOptions);
|
|
97
|
+
context.signal.throwIfAborted();
|
|
98
|
+
}
|
|
99
|
+
stat = existing;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw failure(`cannot open ${quote(operand)} for writing`, error);
|
|
103
|
+
}
|
|
104
|
+
let size = args.size ?? reference;
|
|
105
|
+
if (args.ioBlocks) {
|
|
106
|
+
let blockSize = "ioBlockSize" in stat ? stat.ioBlockSize : undefined;
|
|
107
|
+
if (blockSize === undefined && options.ioBlockSize) {
|
|
108
|
+
try {
|
|
109
|
+
context.signal.throwIfAborted();
|
|
110
|
+
blockSize = await options.ioBlockSize(path, stat, context);
|
|
111
|
+
context.signal.throwIfAborted();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw failure(`cannot get the I/O block size of ${quote(operand)}`, error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (blockSize === undefined)
|
|
118
|
+
throw new TruncateError(`cannot truncate ${quote(operand)}: Operation not supported (I/O block size is unavailable)`);
|
|
119
|
+
if (typeof blockSize !== "number" || !Number.isSafeInteger(blockSize) || blockSize <= 0)
|
|
120
|
+
throw new TruncateError(`cannot truncate ${quote(operand)}: Operation not supported (invalid I/O block size)`);
|
|
121
|
+
const scaled = size * BigInt(blockSize);
|
|
122
|
+
if (scaled > maximumSize || scaled < minimumSize)
|
|
123
|
+
throw new TruncateError(`overflow in ${size} * ${blockSize} byte blocks for file ${quote(operand)}`);
|
|
124
|
+
size = scaled;
|
|
125
|
+
}
|
|
126
|
+
if (args.mode !== "absolute") {
|
|
127
|
+
const base = reference ?? await measuredSize(context, path, stat, operand, options);
|
|
128
|
+
if (args.mode === "<")
|
|
129
|
+
size = base < size ? base : size;
|
|
130
|
+
else if (args.mode === ">")
|
|
131
|
+
size = base > size ? base : size;
|
|
132
|
+
else if (args.mode === "/")
|
|
133
|
+
size = base - base % size;
|
|
134
|
+
else {
|
|
135
|
+
if (args.mode === "%")
|
|
136
|
+
size = base % size === 0n ? 0n : size - base % size;
|
|
137
|
+
size += base;
|
|
138
|
+
if (size > maximumSize || size < minimumSize)
|
|
139
|
+
throw new TruncateError(`overflow extending size of file ${quote(operand)}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (size < 0n)
|
|
143
|
+
size = 0n;
|
|
144
|
+
if (size > BigInt(Number.MAX_SAFE_INTEGER))
|
|
145
|
+
throw new TruncateError(`failed to truncate ${quote(operand)} at ${size} bytes: Operation not supported (size exceeds exact filesystem integer range)`);
|
|
146
|
+
try {
|
|
147
|
+
context.signal.throwIfAborted();
|
|
148
|
+
await context.fs.truncate(path, Number(size), fsOptions);
|
|
149
|
+
context.signal.throwIfAborted();
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw failure(`failed to truncate ${quote(operand)} at ${size} bytes`, error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function executeInvocation(context, settings) {
|
|
156
|
+
context.signal.throwIfAborted();
|
|
157
|
+
const report = async (error) => {
|
|
158
|
+
context.signal.throwIfAborted();
|
|
159
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
160
|
+
const diagnostic = `truncate: ${message}\n${error instanceof TruncateError && error.usage ? "Try 'truncate --help' for more information.\n" : ""}`;
|
|
161
|
+
await writeBytes(context.stderr, error instanceof TruncateError && error.raw ? argumentBytes(diagnostic) : new TextEncoder().encode(diagnostic), context.signal);
|
|
162
|
+
};
|
|
163
|
+
let args, reference;
|
|
164
|
+
try {
|
|
165
|
+
args = parseArguments(context.args, Object.hasOwn(context.env, "POSIXLY_CORRECT"), getCommandArguments(context));
|
|
166
|
+
if (args.display) {
|
|
167
|
+
await writeBytes(context.stdout, new TextEncoder().encode(args.display === "help" ? helpText : "truncate (safe-bash; GNU coreutils 9.7 semantics)\n"), context.signal);
|
|
168
|
+
return { exitCode: 0 };
|
|
169
|
+
}
|
|
170
|
+
if (args.reference !== undefined) {
|
|
171
|
+
let stat;
|
|
172
|
+
try {
|
|
173
|
+
stat = await context.fs.stat(operandPath(context, args.reference), { signal: context.signal });
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
throw failure(`cannot stat ${quote(args.reference)}`, error);
|
|
177
|
+
}
|
|
178
|
+
reference = await measuredSize(context, operandPath(context, args.reference), stat, args.reference, settings);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
await report(error);
|
|
183
|
+
return { exitCode: 1 };
|
|
184
|
+
}
|
|
185
|
+
let exitCode = 0;
|
|
186
|
+
let completed = 0;
|
|
187
|
+
for (const operand of args.files) {
|
|
188
|
+
context.signal.throwIfAborted();
|
|
189
|
+
try {
|
|
190
|
+
await truncateFile(context, args, operand, reference, settings);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
await report(error);
|
|
194
|
+
exitCode = 1;
|
|
195
|
+
}
|
|
196
|
+
if (++completed % 64 === 0)
|
|
197
|
+
await yieldTurn(context.signal);
|
|
198
|
+
}
|
|
199
|
+
return { exitCode };
|
|
200
|
+
}
|
|
201
|
+
export function createTruncateCommand(options = {}) {
|
|
202
|
+
const settings = { ...options };
|
|
203
|
+
return {
|
|
204
|
+
name: "truncate",
|
|
205
|
+
runtimeIdentity: commandRuntimeIdentity,
|
|
206
|
+
filesystemRequirements: [
|
|
207
|
+
{ id: "resize", description: "Resize existing files", capabilities: ["stat", "truncate"], mutates: true },
|
|
208
|
+
{ id: "create", description: "Create missing files without replacing existing bytes", capabilities: ["stat", "truncate", "append"], mutates: true },
|
|
209
|
+
],
|
|
210
|
+
async execute(context) {
|
|
211
|
+
const controller = new AbortController();
|
|
212
|
+
let pending;
|
|
213
|
+
let cleanup;
|
|
214
|
+
const close = () => {
|
|
215
|
+
controller.abort(new Error("truncate invocation is closed"));
|
|
216
|
+
return cleanup ??= (async () => { await pending?.catch(() => { }); })();
|
|
217
|
+
};
|
|
218
|
+
context.registerCleanup?.(close);
|
|
219
|
+
const invocation = context.registerCleanup ? { ...context, signal: AbortSignal.any([context.signal, controller.signal]) } : context;
|
|
220
|
+
try {
|
|
221
|
+
pending = Promise.resolve().then(() => executeInvocation(invocation, settings));
|
|
222
|
+
return await pending;
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
await close();
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export function createTruncateCommands(options = {}) {
|
|
231
|
+
return [createTruncateCommand(options)];
|
|
232
|
+
}
|
|
233
|
+
export function truncateCommands(options = {}) {
|
|
234
|
+
const commands = createTruncateCommands(options), replace = options.replace ?? false;
|
|
235
|
+
return { name: "truncate-commands", setup(host) {
|
|
236
|
+
if (!replace)
|
|
237
|
+
for (const command of commands) {
|
|
238
|
+
if (host.commands.has(command.name))
|
|
239
|
+
throw new Error(`Command already registered: ${command.name}`);
|
|
240
|
+
}
|
|
241
|
+
for (const command of commands)
|
|
242
|
+
host.commands.register(command, { replace });
|
|
243
|
+
} };
|
|
244
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CommandDefinition, type VirtualShellPlugin } from "@poe-platform/safe-bash/contracts/index";
|
|
2
|
+
export interface YesCommandOptions {
|
|
3
|
+
readonly maxRecordBytes?: number | undefined;
|
|
4
|
+
readonly chunkBytes?: number | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface YesCommandsOptions extends YesCommandOptions {
|
|
7
|
+
readonly replace?: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function createYesCommand(options?: YesCommandOptions): CommandDefinition;
|
|
10
|
+
export declare function createYesCommands(options?: YesCommandOptions): readonly CommandDefinition[];
|
|
11
|
+
export declare function yesCommands(options?: YesCommandsOptions): VirtualShellPlugin;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { commandRuntimeIdentity, FsError, getCommandArguments, isFsError, writeBytes, } from "@poe-platform/safe-bash/contracts/index";
|
|
2
|
+
import { shellValueByteLength } from "@poe-platform/safe-bash/contracts/value";
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const help = "Usage: yes [STRING]...\n or: yes OPTION\nRepeatedly output a line with all specified STRING(s), or 'y'.\n\n --help display this help and exit\n --version output version information and exit\n\nGNU coreutils online help: <https://www.gnu.org/software/coreutils/>\nReport any translation bugs to <https://translationproject.org/team/>\nFull documentation <https://www.gnu.org/software/coreutils/yes>\nor available locally via: info '(coreutils) yes invocation'\n";
|
|
5
|
+
const version = "yes (virtual-bash GNU-compatible profile)\n";
|
|
6
|
+
function select(context) {
|
|
7
|
+
for (let index = 0; index < context.args.length; index++) {
|
|
8
|
+
const argument = context.args[index];
|
|
9
|
+
if (argument === "--")
|
|
10
|
+
return { kind: "repeat", delimiter: index };
|
|
11
|
+
if (argument === "-" || !argument.startsWith("-")) {
|
|
12
|
+
if (Object.hasOwn(context.env, "POSIXLY_CORRECT"))
|
|
13
|
+
break;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (!argument.startsWith("--")) {
|
|
17
|
+
return { kind: "error", prefix: "invalid option -- '", suffix: "'", argument: index, short: true };
|
|
18
|
+
}
|
|
19
|
+
const equals = argument.indexOf("=");
|
|
20
|
+
const name = argument.slice(2, equals < 0 ? undefined : equals);
|
|
21
|
+
if (!name) {
|
|
22
|
+
return { kind: "error", prefix: "option '", suffix: "' is ambiguous; possibilities: '--help' '--version'", argument: index };
|
|
23
|
+
}
|
|
24
|
+
const option = "help".startsWith(name) ? "help" : "version".startsWith(name) ? "version" : undefined;
|
|
25
|
+
if (!option)
|
|
26
|
+
return { kind: "error", prefix: "unrecognized option '", suffix: "'", argument: index };
|
|
27
|
+
if (equals >= 0)
|
|
28
|
+
return { kind: "error", prefix: `option '--${option}' doesn't allow an argument`, suffix: "" };
|
|
29
|
+
return { kind: "text", text: option === "help" ? help : version };
|
|
30
|
+
}
|
|
31
|
+
return { kind: "repeat", delimiter: -1 };
|
|
32
|
+
}
|
|
33
|
+
export function createYesCommand(options = {}) {
|
|
34
|
+
if (options === null || typeof options !== "object" || Array.isArray(options))
|
|
35
|
+
throw new TypeError("Yes options must be an object");
|
|
36
|
+
const { maxRecordBytes = 1024 * 1024, chunkBytes = 16384 } = options;
|
|
37
|
+
for (const [name, value] of Object.entries({ maxRecordBytes, chunkBytes })) {
|
|
38
|
+
if (typeof value !== "number")
|
|
39
|
+
throw new TypeError(`Yes ${name} must be a number`);
|
|
40
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 16 * 1024 * 1024) {
|
|
41
|
+
throw new RangeError(`Yes ${name} must be an integer from 1 to 16777216`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
name: "yes",
|
|
46
|
+
runtimeIdentity: commandRuntimeIdentity,
|
|
47
|
+
description: "Repeat a line until canceled or its output consumer closes",
|
|
48
|
+
async execute(context) {
|
|
49
|
+
context.signal.throwIfAborted();
|
|
50
|
+
const supplied = context.argumentValues === undefined ? undefined : getCommandArguments(context);
|
|
51
|
+
const selected = select(context);
|
|
52
|
+
if (selected.kind === "error") {
|
|
53
|
+
const argv = supplied ?? getCommandArguments(context);
|
|
54
|
+
if (selected.argument !== undefined && shellValueByteLength(argv.values[selected.argument]) > maxRecordBytes) {
|
|
55
|
+
await writeBytes(context.stderr, encoder.encode("yes: record exceeds maxRecordBytes\n"), context.signal);
|
|
56
|
+
return { exitCode: 1 };
|
|
57
|
+
}
|
|
58
|
+
await writeBytes(context.stderr, encoder.encode(`yes: ${selected.prefix}`), context.signal);
|
|
59
|
+
if (selected.argument !== undefined) {
|
|
60
|
+
const bytes = argv.bytes(selected.argument);
|
|
61
|
+
await writeBytes(context.stderr, selected.short ? bytes.subarray(1, 2) : bytes, context.signal);
|
|
62
|
+
}
|
|
63
|
+
await writeBytes(context.stderr, encoder.encode(`${selected.suffix}\nTry 'yes --help' for more information.\n`), context.signal);
|
|
64
|
+
return { exitCode: 1 };
|
|
65
|
+
}
|
|
66
|
+
let record;
|
|
67
|
+
if (selected.kind === "text")
|
|
68
|
+
record = encoder.encode(selected.text);
|
|
69
|
+
else {
|
|
70
|
+
const values = supplied?.values ?? context.args;
|
|
71
|
+
let length = values.length - (selected.delimiter < 0 ? 0 : 1);
|
|
72
|
+
for (let index = 0; index < values.length && length <= maxRecordBytes; index++) {
|
|
73
|
+
if (index !== selected.delimiter)
|
|
74
|
+
length += shellValueByteLength(values[index]);
|
|
75
|
+
}
|
|
76
|
+
if (values.length === (selected.delimiter < 0 ? 0 : 1))
|
|
77
|
+
length = 2;
|
|
78
|
+
if (length > maxRecordBytes) {
|
|
79
|
+
await writeBytes(context.stderr, encoder.encode("yes: record exceeds maxRecordBytes\n"), context.signal);
|
|
80
|
+
return { exitCode: 1 };
|
|
81
|
+
}
|
|
82
|
+
const argv = supplied ?? getCommandArguments(context);
|
|
83
|
+
record = new Uint8Array(length);
|
|
84
|
+
let offset = 0;
|
|
85
|
+
for (let index = 0; index < argv.values.length; index++) {
|
|
86
|
+
if (index === selected.delimiter)
|
|
87
|
+
continue;
|
|
88
|
+
const bytes = argv.bytes(index);
|
|
89
|
+
record.set(bytes, offset);
|
|
90
|
+
offset += bytes.length;
|
|
91
|
+
record[offset++] = 32;
|
|
92
|
+
}
|
|
93
|
+
if (!offset)
|
|
94
|
+
record[0] = 121;
|
|
95
|
+
record[record.length - 1] = 10;
|
|
96
|
+
if (record.length <= chunkBytes / 2) {
|
|
97
|
+
const batch = new Uint8Array(Math.floor(chunkBytes / record.length) * record.length);
|
|
98
|
+
for (let start = 0; start < batch.length; start += record.length)
|
|
99
|
+
batch.set(record, start);
|
|
100
|
+
record = batch;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let timer;
|
|
104
|
+
let resume;
|
|
105
|
+
let closed = false;
|
|
106
|
+
const cleanup = () => {
|
|
107
|
+
closed = true;
|
|
108
|
+
if (timer !== undefined)
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
timer = undefined;
|
|
111
|
+
const pending = resume;
|
|
112
|
+
resume = undefined;
|
|
113
|
+
pending?.();
|
|
114
|
+
};
|
|
115
|
+
context.registerCleanup?.(cleanup);
|
|
116
|
+
try {
|
|
117
|
+
do {
|
|
118
|
+
for (let offset = 0; offset < record.length; offset += chunkBytes) {
|
|
119
|
+
context.signal.throwIfAborted();
|
|
120
|
+
if (closed)
|
|
121
|
+
throw new FsError("ECANCELED");
|
|
122
|
+
await writeBytes(context.stdout, record.subarray(offset, Math.min(offset + chunkBytes, record.length)), context.signal);
|
|
123
|
+
context.signal.throwIfAborted();
|
|
124
|
+
if (selected.kind === "repeat") {
|
|
125
|
+
if (closed)
|
|
126
|
+
throw new FsError("ECANCELED");
|
|
127
|
+
await new Promise(resolve => {
|
|
128
|
+
resume = resolve;
|
|
129
|
+
timer = setTimeout(() => { timer = undefined; resume = undefined; resolve(); }, 0);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} while (selected.kind === "repeat");
|
|
134
|
+
return { exitCode: 0 };
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
context.signal.throwIfAborted();
|
|
138
|
+
if (!isFsError(error) || error.code === "EPIPE" || closed)
|
|
139
|
+
throw error;
|
|
140
|
+
const description = error.code === "EIO" ? "Input/output error"
|
|
141
|
+
: error.code === "ENOSPC" ? "No space left on device"
|
|
142
|
+
: error.code === "EBADF" ? "Bad file descriptor" : error.message;
|
|
143
|
+
await writeBytes(context.stderr, encoder.encode(`yes: standard output: ${description}\n`), context.signal);
|
|
144
|
+
return { exitCode: 1 };
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
cleanup();
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
export function createYesCommands(options = {}) {
|
|
153
|
+
return Object.freeze([createYesCommand(options)]);
|
|
154
|
+
}
|
|
155
|
+
export function yesCommands(options = {}) {
|
|
156
|
+
const commands = createYesCommands(options);
|
|
157
|
+
const { replace = false } = options;
|
|
158
|
+
if (typeof replace !== "boolean")
|
|
159
|
+
throw new TypeError("Yes replace must be a boolean");
|
|
160
|
+
return {
|
|
161
|
+
name: "yes-commands",
|
|
162
|
+
setup(host) {
|
|
163
|
+
for (const command of commands)
|
|
164
|
+
host.commands.register(command, { replace });
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { getCommandArguments } from "@poe-platform/safe-bash/contracts/index";
|
|
2
|
+
import { MikeError } from "./native-work.js";
|
|
3
|
+
export const mikeEvalHelp = "yq is a portable command-line data file processor (https://github.com/mikefarah/yq/) \nSee https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.\n\n## Evaluate Sequence ##\nThis command iterates over each yaml document from each given file, applies the \nexpression and prints the result in sequence.\n\nUsage:\n yq eval [expression] [yaml_file1]... [flags]\n\nAliases:\n eval, e\n\nExamples:\n\n# Reads field under the given path for each file\nyq e '.a.b' f1.yml f2.yml \n\n# Prints out the file\nyq e sample.yaml \n\n# Pipe from STDIN\n## use '-' as a filename to pipe from STDIN\ncat file2.yml | yq e '.a.b' file1.yml - file3.yml\n\n# Creates a new yaml document\n## Note that editing an empty file does not work.\nyq e -n '.a.b.c = \"cat\"' \n\n# Update a file in place\nyq e '.a.b = \"cool\"' -i file.yaml \n\n\nFlags:\n -h, --help help for eval\n\nGlobal Flags:\n -C, --colors force print with colors\n --csv-auto-parse parse CSV YAML/JSON values (default true)\n --csv-separator char CSV Separator character (default ,)\n --debug-node-info debug node info\n -e, --exit-status set exit status if there are no matches or null or false is returned\n --expression string forcibly set the expression argument. Useful when yq argument detection thinks your expression is a file.\n --from-file string Load expression from specified file.\n -f, --front-matter string (extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact\n --header-preprocess Slurp any header comments and separators before processing expression. (default true)\n -I, --indent int sets indent level for output (default 2)\n --ini-preserve-quotes preserve surrounding quotes on INI values during round-trip\n -i, --inplace update the file in place of first file given.\n -p, --input-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|lua|l|ini|i] parse format for input. (default \"auto\")\n --lua-globals output keys as top-level global variables\n --lua-prefix string prefix (default \"return \")\n --lua-suffix string suffix (default \";\\n\")\n --lua-unquoted output unquoted string keys (e.g. {foo=\"bar\"})\n -M, --no-colors force print with no colors\n -N, --no-doc Don't print document separators (---)\n -0, --nul-output Use NUL char to separate values. If unwrap scalar is also set, fail if unwrapped scalar contains NUL char.\n -n, --null-input Don't read input, simply evaluate the expression given. Useful for creating docs from scratch.\n -o, --output-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|shell|s|lua|l|ini|i] output format type. (default \"auto\")\n -P, --prettyPrint pretty print, shorthand for '... style = \"\"'\n --properties-array-brackets use [x] in array paths (e.g. for SpringBoot)\n --properties-separator string separator to use between keys and values (default \" = \")\n --security-disable-env-ops Disable env related operations.\n --security-disable-file-ops Disable file related operations (e.g. load)\n --security-enable-system-operator Enable system operator to allow execution of external commands.\n --shell-key-separator string separator for shell variable key paths (default \"_\")\n -s, --split-exp string print each result (or doc) into a file named (exp). [exp] argument must return a string. You can use $index in the expression as the result counter. The necessary directories will be created.\n --split-exp-file string Use a file to specify the split-exp expression.\n --string-interpolation Toggles strings interpolation of \\(exp) (default true)\n --tsv-auto-parse parse TSV YAML/JSON values (default true)\n -r, --unwrapScalar unwrap scalar, print the value with no quotes, colours or comments. Defaults to true for yaml (default true)\n -v, --verbose verbose mode\n --xml-attribute-prefix string prefix for xml attributes (default \"+@\")\n --xml-content-name string name for xml content (if no attribute name is present). (default \"+content\")\n --xml-directive-name string name for xml directives (e.g. <!DOCTYPE thing cat>) (default \"+directive\")\n --xml-keep-namespace enables keeping namespace after parsing attributes (default true)\n --xml-proc-inst-prefix string prefix for xml processing instructions (e.g. <?xml version=\"1\"?>) (default \"+p_\")\n --xml-raw-token enables using RawToken method instead Token. Commonly disables namespace translations. See https://pkg.go.dev/encoding/xml#Decoder.RawToken for details. (default true)\n --xml-skip-directives skip over directives (e.g. <!DOCTYPE thing cat>)\n --xml-skip-proc-inst skip over process instructions (e.g. <?xml version=\"1\"?>)\n --xml-strict-mode enables strict parsing of XML. See https://pkg.go.dev/encoding/xml for more details.\n -c, --yaml-compact-seq-indent Use compact sequence indentation where '- ' is considered part of the indentation.\n --yaml-fix-merge-anchor-to-spec Fix merge anchor to match YAML spec. Will default to true in late 2025\n";
|
|
4
|
+
export const mikeAllHelp = "yq is a portable command-line data file processor (https://github.com/mikefarah/yq/) \nSee https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.\n\n## Evaluate All ##\nThis command loads _all_ yaml documents of _all_ yaml files and runs expression once\nUseful when you need to run an expression across several yaml documents or files (like merge).\nNote that it consumes more memory than eval.\n\nUsage:\n yq eval-all [expression] [yaml_file1]... [flags]\n\nAliases:\n eval-all, ea\n\nExamples:\n\n# Merge f2.yml into f1.yml (in place)\nyq eval-all --inplace 'select(fileIndex == 0) * select(fileIndex == 1)' f1.yml f2.yml\n## the same command and expression using shortened names:\nyq ea -i 'select(fi == 0) * select(fi == 1)' f1.yml f2.yml\n\n\n# Merge all given files\nyq ea '. as $item ireduce ({}; . * $item )' file1.yml file2.yml ...\n\n# Pipe from STDIN\n## use '-' as a filename to pipe from STDIN\ncat file2.yml | yq ea '.a.b' file1.yml - file3.yml\n\n\nFlags:\n -h, --help help for eval-all\n\nGlobal Flags:\n -C, --colors force print with colors\n --csv-auto-parse parse CSV YAML/JSON values (default true)\n --csv-separator char CSV Separator character (default ,)\n --debug-node-info debug node info\n -e, --exit-status set exit status if there are no matches or null or false is returned\n --expression string forcibly set the expression argument. Useful when yq argument detection thinks your expression is a file.\n --from-file string Load expression from specified file.\n -f, --front-matter string (extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact\n --header-preprocess Slurp any header comments and separators before processing expression. (default true)\n -I, --indent int sets indent level for output (default 2)\n --ini-preserve-quotes preserve surrounding quotes on INI values during round-trip\n -i, --inplace update the file in place of first file given.\n -p, --input-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|lua|l|ini|i] parse format for input. (default \"auto\")\n --lua-globals output keys as top-level global variables\n --lua-prefix string prefix (default \"return \")\n --lua-suffix string suffix (default \";\\n\")\n --lua-unquoted output unquoted string keys (e.g. {foo=\"bar\"})\n -M, --no-colors force print with no colors\n -N, --no-doc Don't print document separators (---)\n -0, --nul-output Use NUL char to separate values. If unwrap scalar is also set, fail if unwrapped scalar contains NUL char.\n -n, --null-input Don't read input, simply evaluate the expression given. Useful for creating docs from scratch.\n -o, --output-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|shell|s|lua|l|ini|i] output format type. (default \"auto\")\n -P, --prettyPrint pretty print, shorthand for '... style = \"\"'\n --properties-array-brackets use [x] in array paths (e.g. for SpringBoot)\n --properties-separator string separator to use between keys and values (default \" = \")\n --security-disable-env-ops Disable env related operations.\n --security-disable-file-ops Disable file related operations (e.g. load)\n --security-enable-system-operator Enable system operator to allow execution of external commands.\n --shell-key-separator string separator for shell variable key paths (default \"_\")\n -s, --split-exp string print each result (or doc) into a file named (exp). [exp] argument must return a string. You can use $index in the expression as the result counter. The necessary directories will be created.\n --split-exp-file string Use a file to specify the split-exp expression.\n --string-interpolation Toggles strings interpolation of \\(exp) (default true)\n --tsv-auto-parse parse TSV YAML/JSON values (default true)\n -r, --unwrapScalar unwrap scalar, print the value with no quotes, colours or comments. Defaults to true for yaml (default true)\n -v, --verbose verbose mode\n --xml-attribute-prefix string prefix for xml attributes (default \"+@\")\n --xml-content-name string name for xml content (if no attribute name is present). (default \"+content\")\n --xml-directive-name string name for xml directives (e.g. <!DOCTYPE thing cat>) (default \"+directive\")\n --xml-keep-namespace enables keeping namespace after parsing attributes (default true)\n --xml-proc-inst-prefix string prefix for xml processing instructions (e.g. <?xml version=\"1\"?>) (default \"+p_\")\n --xml-raw-token enables using RawToken method instead Token. Commonly disables namespace translations. See https://pkg.go.dev/encoding/xml#Decoder.RawToken for details. (default true)\n --xml-skip-directives skip over directives (e.g. <!DOCTYPE thing cat>)\n --xml-skip-proc-inst skip over process instructions (e.g. <?xml version=\"1\"?>)\n --xml-strict-mode enables strict parsing of XML. See https://pkg.go.dev/encoding/xml for more details.\n -c, --yaml-compact-seq-indent Use compact sequence indentation where '- ' is considered part of the indentation.\n --yaml-fix-merge-anchor-to-spec Fix merge anchor to match YAML spec. Will default to true in late 2025\n";
|
|
5
|
+
export const mikeHelp = "yq is a portable command-line data file processor (https://github.com/mikefarah/yq/) \nSee https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.\n\nUsage:\n yq [flags]\n yq [command]\n\nExamples:\n\n# yq tries to auto-detect the file format based off the extension, and defaults to YAML if it's unknown (or piping through STDIN)\n# Use the '-p/--input-format' flag to specify a format type.\ncat file.xml | yq -p xml\n\n# read the \"stuff\" node from \"myfile.yml\"\nyq '.stuff' < myfile.yml\n\n# update myfile.yml in place\nyq -i '.stuff = \"foo\"' myfile.yml\n\n# print contents of sample.json as idiomatic YAML\nyq -P -oy sample.json\n\n\nAvailable Commands:\n completion Generate the autocompletion script for the specified shell\n eval (default) Apply the expression to each document in each yaml file in sequence\n eval-all Loads _all_ yaml documents of _all_ yaml files and runs expression once\n help Help about any command\n\nFlags:\n -C, --colors force print with colors\n --csv-auto-parse parse CSV YAML/JSON values (default true)\n --csv-separator char CSV Separator character (default ,)\n --debug-node-info debug node info\n -e, --exit-status set exit status if there are no matches or null or false is returned\n --expression string forcibly set the expression argument. Useful when yq argument detection thinks your expression is a file.\n --from-file string Load expression from specified file.\n -f, --front-matter string (extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact\n --header-preprocess Slurp any header comments and separators before processing expression. (default true)\n -h, --help help for yq\n -I, --indent int sets indent level for output (default 2)\n --ini-preserve-quotes preserve surrounding quotes on INI values during round-trip\n -i, --inplace update the file in place of first file given.\n -p, --input-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|lua|l|ini|i] parse format for input. (default \"auto\")\n --lua-globals output keys as top-level global variables\n --lua-prefix string prefix (default \"return \")\n --lua-suffix string suffix (default \";\\n\")\n --lua-unquoted output unquoted string keys (e.g. {foo=\"bar\"})\n -M, --no-colors force print with no colors\n -N, --no-doc Don't print document separators (---)\n -0, --nul-output Use NUL char to separate values. If unwrap scalar is also set, fail if unwrapped scalar contains NUL char.\n -n, --null-input Don't read input, simply evaluate the expression given. Useful for creating docs from scratch.\n -o, --output-format string [auto|a|yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|shell|s|lua|l|ini|i] output format type. (default \"auto\")\n -P, --prettyPrint pretty print, shorthand for '... style = \"\"'\n --properties-array-brackets use [x] in array paths (e.g. for SpringBoot)\n --properties-separator string separator to use between keys and values (default \" = \")\n --security-disable-env-ops Disable env related operations.\n --security-disable-file-ops Disable file related operations (e.g. load)\n --security-enable-system-operator Enable system operator to allow execution of external commands.\n --shell-key-separator string separator for shell variable key paths (default \"_\")\n -s, --split-exp string print each result (or doc) into a file named (exp). [exp] argument must return a string. You can use $index in the expression as the result counter. The necessary directories will be created.\n --split-exp-file string Use a file to specify the split-exp expression.\n --string-interpolation Toggles strings interpolation of \\(exp) (default true)\n --tsv-auto-parse parse TSV YAML/JSON values (default true)\n -r, --unwrapScalar unwrap scalar, print the value with no quotes, colours or comments. Defaults to true for yaml (default true)\n -v, --verbose verbose mode\n -V, --version Print version information and quit\n --xml-attribute-prefix string prefix for xml attributes (default \"+@\")\n --xml-content-name string name for xml content (if no attribute name is present). (default \"+content\")\n --xml-directive-name string name for xml directives (e.g. <!DOCTYPE thing cat>) (default \"+directive\")\n --xml-keep-namespace enables keeping namespace after parsing attributes (default true)\n --xml-proc-inst-prefix string prefix for xml processing instructions (e.g. <?xml version=\"1\"?>) (default \"+p_\")\n --xml-raw-token enables using RawToken method instead Token. Commonly disables namespace translations. See https://pkg.go.dev/encoding/xml#Decoder.RawToken for details. (default true)\n --xml-skip-directives skip over directives (e.g. <!DOCTYPE thing cat>)\n --xml-skip-proc-inst skip over process instructions (e.g. <?xml version=\"1\"?>)\n --xml-strict-mode enables strict parsing of XML. See https://pkg.go.dev/encoding/xml for more details.\n -c, --yaml-compact-seq-indent Use compact sequence indentation where '- ' is considered part of the indentation.\n --yaml-fix-merge-anchor-to-spec Fix merge anchor to match YAML spec. Will default to true in late 2025\n\nUse \"yq [command] --help\" for more information about a command.\n";
|
|
6
|
+
export const mikeUsage = mikeHelp.slice(mikeHelp.indexOf("Usage:")) + "\n";
|
|
7
|
+
const booleans = {
|
|
8
|
+
n: "nullInput", "null-input": "nullInput", i: "inplace", inplace: "inplace",
|
|
9
|
+
e: "exitStatus", "exit-status": "exitStatus", r: "unwrap", unwrapScalar: "unwrap",
|
|
10
|
+
h: "help", help: "help", V: "version", version: "version", N: "noDoc", "no-doc": "noDoc",
|
|
11
|
+
c: "compactSequence", "yaml-compact-seq-indent": "compactSequence", "yaml-fix-merge-anchor-to-spec": "mergeSpec",
|
|
12
|
+
};
|
|
13
|
+
const values = {
|
|
14
|
+
p: "input", "input-format": "input", o: "output", "output-format": "output", I: "indent", indent: "indent", expression: "expression",
|
|
15
|
+
};
|
|
16
|
+
export function mikeCommandMode(args) {
|
|
17
|
+
if (args.length > 4096)
|
|
18
|
+
return "root";
|
|
19
|
+
let bytes = 0;
|
|
20
|
+
for (let index = 0; index < args.length; index++) {
|
|
21
|
+
const argument = args[index];
|
|
22
|
+
bytes += Buffer.byteLength(argument);
|
|
23
|
+
if (bytes > 65536)
|
|
24
|
+
return "root";
|
|
25
|
+
if (argument === "--")
|
|
26
|
+
return index + 1 < args.length ? "eval" : "root";
|
|
27
|
+
if (!argument.startsWith("-") || argument === "-")
|
|
28
|
+
return argument === "ea" || argument === "eval-all" ? "eval-all" : "eval";
|
|
29
|
+
const long = argument.startsWith("--");
|
|
30
|
+
let remaining = argument.slice(long ? 2 : 1);
|
|
31
|
+
while (remaining) {
|
|
32
|
+
const equal = remaining.indexOf("=");
|
|
33
|
+
const name = long ? equal < 0 ? remaining : remaining.slice(0, equal) : remaining[0];
|
|
34
|
+
if (Object.hasOwn(values, name)) {
|
|
35
|
+
if (long ? equal < 0 : remaining.length === 1)
|
|
36
|
+
index++;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (!Object.hasOwn(booleans, name) && name !== "M" && name !== "no-colors")
|
|
40
|
+
return "root";
|
|
41
|
+
if (long || remaining[1] === "=")
|
|
42
|
+
break;
|
|
43
|
+
remaining = remaining.slice(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return "root";
|
|
47
|
+
}
|
|
48
|
+
function parseIndent(value) {
|
|
49
|
+
const negative = value.startsWith("-");
|
|
50
|
+
let digits = value.startsWith("+") || negative ? value.slice(1) : value;
|
|
51
|
+
let base = 10;
|
|
52
|
+
let prefixed = false;
|
|
53
|
+
if (digits.length > 1 && digits[0] === "0") {
|
|
54
|
+
prefixed = true;
|
|
55
|
+
const prefix = digits[1].toLowerCase();
|
|
56
|
+
base = prefix === "x" ? 16 : prefix === "b" ? 2 : 8;
|
|
57
|
+
digits = digits.slice(prefix === "x" || prefix === "b" || prefix === "o" ? 2 : 1);
|
|
58
|
+
}
|
|
59
|
+
if (prefixed && digits.startsWith("_"))
|
|
60
|
+
digits = digits.slice(1);
|
|
61
|
+
let invalid = digits.length === 0;
|
|
62
|
+
let previousDigit = false;
|
|
63
|
+
let integer = 0n;
|
|
64
|
+
const maximum = negative ? 9223372036854775808n : 9223372036854775807n;
|
|
65
|
+
for (const character of digits) {
|
|
66
|
+
if (character === "_") {
|
|
67
|
+
if (!previousDigit)
|
|
68
|
+
invalid = true;
|
|
69
|
+
previousDigit = false;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const digit = "0123456789abcdef".indexOf(character.toLowerCase());
|
|
73
|
+
if (digit < 0 || digit >= base)
|
|
74
|
+
invalid = true;
|
|
75
|
+
else if (integer <= maximum)
|
|
76
|
+
integer = integer * BigInt(base) + BigInt(digit);
|
|
77
|
+
previousDigit = true;
|
|
78
|
+
}
|
|
79
|
+
if (!previousDigit)
|
|
80
|
+
invalid = true;
|
|
81
|
+
if (invalid || integer > maximum)
|
|
82
|
+
throw new MikeError(`invalid argument ${JSON.stringify(value)} for "-I, --indent" flag: strconv.ParseInt: parsing ${JSON.stringify(value)}: ${invalid ? "invalid syntax" : "value out of range"}`, true);
|
|
83
|
+
const result = Number(negative ? -integer : integer);
|
|
84
|
+
if (!Number.isSafeInteger(result))
|
|
85
|
+
throw new MikeError("yq limit exceeded: indent");
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
export function parseMikeArguments(context) {
|
|
89
|
+
if (context.args.length > 4096)
|
|
90
|
+
throw new MikeError("yq limit exceeded: argument count");
|
|
91
|
+
let bytes = 0;
|
|
92
|
+
for (const argument of context.args) {
|
|
93
|
+
bytes += Buffer.byteLength(argument);
|
|
94
|
+
if (bytes > 65536)
|
|
95
|
+
throw new MikeError("yq limit exceeded: argument bytes");
|
|
96
|
+
}
|
|
97
|
+
const carrier = getCommandArguments(context);
|
|
98
|
+
for (let index = 0; index < carrier.args.length; index++) {
|
|
99
|
+
try {
|
|
100
|
+
new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(carrier.bytes(index));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
throw new MikeError("yq filename/expression bytes must be valid UTF-8");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const result = { all: false, help: false, version: false, nullInput: false, inplace: false,
|
|
107
|
+
exitStatus: false, input: "auto", output: "auto", indent: 2, unwrap: undefined, noDoc: false,
|
|
108
|
+
compactSequence: false, mergeSpec: false, expression: undefined, operands: [] };
|
|
109
|
+
let ended = false;
|
|
110
|
+
for (let index = 0; index < context.args.length; index++) {
|
|
111
|
+
const argument = context.args[index];
|
|
112
|
+
if (!ended && argument === "--") {
|
|
113
|
+
ended = true;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (!ended && ["eval", "e", "eval-all", "ea"].includes(argument) && result.operands.length === 0) {
|
|
117
|
+
result.all = argument === "eval-all" || argument === "ea";
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (ended || !argument.startsWith("-") || argument === "-") {
|
|
121
|
+
result.operands.push(argument);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const long = argument.startsWith("--");
|
|
125
|
+
let remaining = argument.slice(long ? 2 : 1);
|
|
126
|
+
while (remaining) {
|
|
127
|
+
const equal = remaining.indexOf("=");
|
|
128
|
+
const name = long ? (equal < 0 ? remaining : remaining.slice(0, equal)) : remaining[0];
|
|
129
|
+
let attached = long ? (equal < 0 ? undefined : remaining.slice(equal + 1)) : remaining.slice(1) || undefined;
|
|
130
|
+
if (!long && attached?.startsWith("="))
|
|
131
|
+
attached = attached.slice(1);
|
|
132
|
+
const boolean = Object.hasOwn(booleans, name) ? booleans[name] : undefined;
|
|
133
|
+
if (boolean || name === "M" || name === "no-colors") {
|
|
134
|
+
const explicit = long ? equal >= 0 : remaining[1] === "=";
|
|
135
|
+
let enabled = true;
|
|
136
|
+
if (explicit) {
|
|
137
|
+
if (["true", "1", "t", "TRUE", "True", "T"].includes(attached))
|
|
138
|
+
enabled = true;
|
|
139
|
+
else if (["false", "0", "f", "FALSE", "False", "F"].includes(attached))
|
|
140
|
+
enabled = false;
|
|
141
|
+
else {
|
|
142
|
+
const fullName = name === "r" || name === "unwrapScalar" ? "-r, --unwrapScalar" : name === "n" || name === "null-input" ? "-n, --null-input" : `--${name}`;
|
|
143
|
+
throw new MikeError(`invalid argument ${JSON.stringify(attached)} for "${fullName}" flag: strconv.ParseBool: parsing ${JSON.stringify(attached)}: invalid syntax`, true);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (boolean)
|
|
147
|
+
Object.assign(result, { [boolean]: enabled });
|
|
148
|
+
remaining = long || explicit ? "" : remaining.slice(1);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const field = Object.hasOwn(values, name) ? values[name] : undefined;
|
|
152
|
+
if (!field)
|
|
153
|
+
throw new MikeError(long ? `unknown flag: --${name}` : `unknown shorthand flag: '${name}' in ${argument}`, true);
|
|
154
|
+
const value = attached ?? context.args[++index];
|
|
155
|
+
if (value === undefined)
|
|
156
|
+
throw new MikeError(long ? `flag needs an argument: --${name}` : `flag needs an argument: '${name}' in ${argument}`, true);
|
|
157
|
+
if (field === "indent") {
|
|
158
|
+
result.indent = parseIndent(value);
|
|
159
|
+
}
|
|
160
|
+
else
|
|
161
|
+
result[field] = value;
|
|
162
|
+
remaining = "";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
export function mikeFormat(value) {
|
|
168
|
+
if (value === "auto" || value === "a" || value === "")
|
|
169
|
+
return "auto";
|
|
170
|
+
if (value === "yaml" || value === "y")
|
|
171
|
+
return "yaml";
|
|
172
|
+
if (value === "json" || value === "j")
|
|
173
|
+
return "json";
|
|
174
|
+
if (["xml", "x", "csv", "c", "tsv", "t", "props", "p", "toml", "ini", "i", "hcl", "h", "lua", "l", "kyaml", "ky", "base64", "uri", "shell", "s"].includes(value))
|
|
175
|
+
throw new MikeError(`format '${value}' is not supported by this bounded yq profile`);
|
|
176
|
+
throw new MikeError(`unknown format '${value}' please use [yaml|y|kyaml|ky|json|j|props|p|csv|c|tsv|t|xml|x|base64|uri|toml|hcl|h|shell|s|lua|l|ini|i]`);
|
|
177
|
+
}
|