import{a as w,b as J}from"./chunk-ZWYFK7P5.js";import"./chunk-OJDRYQWQ.js";import{k as q}from"./chunk-PSW6BMXW.js";import"./chunk-YNYSPYQ5.js";import{a as N}from"./chunk-7L36YK2X.js";import"./chunk-NUFRM6SI.js";import{a as C,b as E,c as x}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";function I(s){let i=[],t=0,o=s.length;for(;t<o;){for(;t<o&&/\s/.test(s[t]);)t++;if(t>=o)break;let a=t,r=s[t];if(r==="{"||r==="["){let n=r,l=r==="{"?"}":"]",c=1,p=!1,d=!1;for(t++;t<o&&c>0;){let h=s[t];d?d=!1:h==="\\"?d=!0:h==='"'?p=!p:p||(h===n?c++:h===l&&c--),t++}if(c!==0)throw new Error(`Unexpected end of JSON input at position ${t} (unclosed ${n})`);i.push(JSON.parse(s.slice(a,t)))}else if(r==='"'){let n=!1;for(t++;t<o;){let l=s[t];if(n)n=!1;else if(l==="\\")n=!0;else if(l==='"'){t++;break}t++}i.push(JSON.parse(s.slice(a,t)))}else if(r==="-"||r>="0"&&r<="9"){for(;t<o&&/[\d.eE+-]/.test(s[t]);)t++;i.push(JSON.parse(s.slice(a,t)))}else if(s.slice(t,t+4)==="true")i.push(!0),t+=4;else if(s.slice(t,t+5)==="false")i.push(!1),t+=5;else if(s.slice(t,t+4)==="null")i.push(null),t+=4;else{let n=s.slice(t,t+10);throw new Error(`Invalid JSON at position ${a}: unexpected '${n.split(/\s/)[0]}'`)}}return i}var H={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output  output strings without quotes","-c, --compact     compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp       read entire input into array","-n, --null-input  don't read any input","-j, --join-output don't print newlines after each output","-a, --ascii       force ASCII output","-S, --sort-keys   sort object keys","-C, --color       colorize output (ignored)","-M, --monochrome  monochrome output (ignored)","    --tab         use tabs for indentation","    --help        display this help and exit"]};function g(s,i,t,o,a,r=0){if(s===null||s===void 0)return"null";if(typeof s=="boolean")return String(s);if(typeof s=="number")return Number.isFinite(s)?String(s):"null";if(typeof s=="string")return t?s:JSON.stringify(s);let n=a?"	":"  ";if(Array.isArray(s))return s.length===0?"[]":i?`[${s.map(c=>g(c,!0,!1,o,a)).join(",")}]`:`[
${s.map(c=>n.repeat(r+1)+g(c,!1,!1,o,a,r+1)).join(`,
`)}
${n.repeat(r)}]`;if(typeof s=="object"){let l=Object.keys(s);return o&&(l=l.sort()),l.length===0?"{}":i?`{${l.map(p=>`${JSON.stringify(p)}:${g(s[p],!0,!1,o,a)}`).join(",")}}`:`{
${l.map(p=>{let d=g(s[p],!1,!1,o,a,r+1);return`${n.repeat(r+1)}${JSON.stringify(p)}: ${d}`}).join(`,
`)}
${n.repeat(r)}}`}return String(s)}var P={name:"jq",async execute(s,i){if(E(s))return C(H);let t=!1,o=!1,a=!1,r=!1,n=!1,l=!1,c=!1,p=!1,d=".",h=!1,j=[];for(let u=0;u<s.length;u++){let e=s[u];if(e==="-r"||e==="--raw-output")t=!0;else if(e==="-c"||e==="--compact-output")o=!0;else if(e==="-e"||e==="--exit-status")a=!0;else if(e==="-s"||e==="--slurp")r=!0;else if(e==="-n"||e==="--null-input")n=!0;else if(e==="-j"||e==="--join-output")l=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")c=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")p=!0;else if(e==="-")j.push("-");else{if(e.startsWith("--"))return x("jq",e);if(e.startsWith("-")){for(let f of e.slice(1))if(f==="r")t=!0;else if(f==="c")o=!0;else if(f==="e")a=!0;else if(f==="s")r=!0;else if(f==="n")n=!0;else if(f==="j")l=!0;else if(f!=="a"){if(f==="S")c=!0;else if(f!=="C"){if(f!=="M")return x("jq",`-${f}`)}}}else h?j.push(e):(d=e,h=!0)}}}}let S=[];if(!n)if(j.length===0||j.length===1&&j[0]==="-")S.push({source:"stdin",content:i.stdin});else{let u=await N(i,j,{cmdName:"jq",stopOnError:!0});if(u.exitCode!==0)return{stdout:"",stderr:u.stderr,exitCode:2};S=u.files.map(e=>({source:e.filename||"stdin",content:e.content}))}try{let u=J(d),e=[],f={limits:i.limits?{maxIterations:i.limits.maxJqIterations}:void 0,env:i.env};if(n)e=w(null,u,f);else if(r){let m=[];for(let{content:$}of S){let y=$.trim();y&&m.push(...I(y))}e=w(m,u,f)}else for(let{content:m}of S){let $=m.trim();if(!$)continue;let y=I($);for(let A of y)e.push(...w(A,u,f))}let b=e.map(m=>g(m,o,t,c,p)),k=l?"":`
`,O=b.join(k),F=a&&(e.length===0||e.every(m=>m==null||m===!1))?1:0;return{stdout:O?l?O:`${O}
`:"",stderr:"",exitCode:F}}catch(u){if(u instanceof q)return{stdout:"",stderr:`jq: ${u.message}
`,exitCode:q.EXIT_CODE};let e=u.message;return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
`,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
`,exitCode:5}}}};export{P as jqCommand};
