Files
QR-master/.output/server/node_modules/just-bash/dist/bundle/chunks/chunk-GE6OQDB2.js
2026-07-15 18:08:51 +02:00

11 lines
8.7 KiB
JavaScript

import{createRequire} from"node:module";const require=createRequire(import.meta.url);
import{a as x}from"./chunk-QAJKDPNS.js";import{a as D,b as ee}from"./chunk-KSBHIW2H.js";import{c as K}from"./chunk-XEKXHOPO.js";import{a as V,b as Y,c as z}from"./chunk-QAYAQNCG.js";var le={name:"grep",summary:"print lines that match patterns",usage:"grep [OPTION]... PATTERN [FILE]...",options:["-E, --extended-regexp PATTERN is an extended regular expression","-P, --perl-regexp PATTERN is a Perl regular expression","-F, --fixed-strings PATTERN is a set of newline-separated strings","-i, --ignore-case ignore case distinctions","-v, --invert-match select non-matching lines","-w, --word-regexp match only whole words","-x, --line-regexp match only whole lines","-c, --count print only a count of matching lines","-l, --files-with-matches print only names of files with matches","-L, --files-without-match print names of files with no matches","-m NUM, --max-count=NUM stop after NUM matches","-n, --line-number print line number with output lines","-h, --no-filename suppress the file name prefix on output","-o, --only-matching show only nonempty parts of lines that match","-q, --quiet, --silent suppress all normal output","-r, -R, --recursive search directories recursively","-A NUM print NUM lines of trailing context","-B NUM print NUM lines of leading context","-C NUM print NUM lines of context","-e PATTERN use PATTERN for matching"," --include=GLOB search only files matching GLOB"," --exclude=GLOB skip files matching GLOB"," --exclude-dir=DIR skip directories matching DIR"," --help display this help and exit"]},te={name:"grep",async execute(t,s){if(Y(t))return V(le);let l=!1,f=!1,u=!1,p=!1,m=!1,a=!1,n=!1,c=!1,y=!1,w=!1,h=!1,d=!1,F=!1,C=!1,I=!1,W=0,P=0,T=0,A=[],E=[],U=[],R=null,H=[];for(let r=0;r<t.length;r++){let i=t[r];if(i.startsWith("-")&&i!=="-"){if(i==="-e"&&r+1<t.length){R=t[++r];continue}if(i.startsWith("--include=")){A.push(i.slice(10));continue}if(i.startsWith("--exclude=")){E.push(i.slice(10));continue}if(i.startsWith("--exclude-dir=")){U.push(i.slice(14));continue}if(i.startsWith("--max-count=")){W=parseInt(i.slice(12),10);continue}let b=i.match(/^-m(\d+)$/);if(b){W=parseInt(b[1],10);continue}if(i==="-m"&&r+1<t.length){W=parseInt(t[++r],10);continue}let o=i.match(/^-([ABC])(\d+)$/);if(o){let e=parseInt(o[2],10);o[1]==="A"?T=e:o[1]==="B"?P=e:o[1]==="C"&&(P=e,T=e);continue}if((i==="-A"||i==="-B"||i==="-C")&&r+1<t.length){let e=parseInt(t[++r],10);i==="-A"?T=e:i==="-B"?P=e:(P=e,T=e);continue}let g=i.startsWith("--")?[i]:i.slice(1).split("");for(let e of g)if(e==="i"||e==="--ignore-case")l=!0;else if(e==="n"||e==="--line-number")f=!0;else if(e==="v"||e==="--invert-match")u=!0;else if(e==="c"||e==="--count")p=!0;else if(e==="l"||e==="--files-with-matches")m=!0;else if(e==="L"||e==="--files-without-match")a=!0;else if(e==="r"||e==="R"||e==="--recursive")n=!0;else if(e==="w"||e==="--word-regexp")c=!0;else if(e==="x"||e==="--line-regexp")y=!0;else if(e==="E"||e==="--extended-regexp")w=!0;else if(e==="P"||e==="--perl-regexp")h=!0;else if(e==="F"||e==="--fixed-strings")d=!0;else if(e==="o"||e==="--only-matching")F=!0;else if(e==="h"||e==="--no-filename")C=!0;else if(e==="q"||e==="--quiet"||e==="--silent")I=!0;else{if(e.startsWith("--"))return z("grep",e);if(e.length===1)return z("grep",`-${e}`)}}else R===null?R=i:H.push(i)}if(R===null)return{stdout:"",stderr:`grep: missing pattern
`,exitCode:2};let ie=d?"fixed":w?"extended":h?"perl":"basic",O,Q,$;try{let r=ee(R,{mode:ie,ignoreCase:l,wholeWord:c,lineRegexp:y});O=r.regex,Q=r.kResetGroup,$=r.preFilter}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${R}
`,exitCode:2}}if(H.length===0&&s.stdin!==void 0){let r=D(K(s.stdin),O,{invertMatch:u,showLineNumbers:f,countOnly:p,filename:"",onlyMatching:F,beforeContext:P,afterContext:T,maxCount:W,kResetGroup:Q,preFilter:$});return I?{stdout:"",stderr:"",exitCode:r.matched?0:1}:{stdout:r.output,stderr:"",exitCode:r.matched?0:1}}if(H.length===0)return{stdout:"",stderr:`grep: no input files
`,exitCode:2};let M="",k="",_=!1,X=!1,v=[];for(let r of H)if(r.includes("*")||r.includes("?")||r.includes("[")){let i=await oe(r,s);if(n)for(let b of i){let o=await L(b.path,s,A,E,U,b.isFile);v.push(...o)}else v.push(...i)}else if(n){let i=await L(r,s,A,E,U);v.push(...i)}else v.push({path:r});let Z=(v.length>1||n)&&!C,j=50;for(let r=0;r<v.length;r+=j){let i=v.slice(r,r+j),b=await Promise.all(i.map(async o=>{let g=o.path,e=g.split("/").pop()||g;if(E.length>0&&!n&&E.some(N=>x(e,N,{stripQuotes:!0}))||A.length>0&&!n&&!A.some(N=>x(e,N,{stripQuotes:!0})))return null;try{let N=s.fs.resolvePath(s.cwd,g),G=!1;if(o.isFile===void 0?G=(await s.fs.stat(N)).isDirectory:G=!o.isFile,G)return n?null:{error:`grep: ${g}: Is a directory
`};let S=await s.fs.readFile(N);if($&&!u){let J=$.ignoreCase?S.toLowerCase():S;if(!$.needles.some(q=>J.includes(q))){if(p){let q=Z?`${g}:0`:"0";return{file:g,result:{output:`${q}
`,matched:!1,matchCount:0}}}return{file:g,result:{output:"",matched:!1,matchCount:0}}}}let re=D(S,O,{invertMatch:u,showLineNumbers:f,countOnly:p,filename:Z?g:"",onlyMatching:F,beforeContext:P,afterContext:T,maxCount:W,kResetGroup:Q,preFilter:$});return{file:g,result:re}}catch{return{error:`grep: ${g}: No such file or directory
`}}}));for(let o of b){if(o===null)continue;if("error"in o&&o.error){k+=o.error,o.error.includes("Is a directory")||(X=!0);continue}if(!("file"in o)||!o.result)continue;let{file:g,result:e}=o;if(e.matched){if(_=!0,I)return{stdout:"",stderr:"",exitCode:0};m?M+=`${g}
`:a||(M+=e.output)}else a?M+=`${g}
`:p&&!m&&(M+=e.output)}}let B;return X?B=2:a?B=M.length>0?0:1:B=_?0:1,I?{stdout:"",stderr:"",exitCode:B}:{stdout:M,stderr:k,exitCode:B}}},se=256;async function ne(t,s,l,f,u=0){if(u>=se)return;let p=l.fs.resolvePath(l.cwd,t);try{if(!(await l.fs.stat(p)).isDirectory){let n=t.split("/").pop()||"";if(s){let c=s.replace(/^\//,"");x(n,c,{stripQuotes:!0})&&f.push(t)}return}let a=await l.fs.readdir(p);for(let n of a){let c=t==="."?n:`${t}/${n}`,y=l.fs.resolvePath(l.cwd,c);if((await l.fs.stat(y)).isDirectory)await ne(c,s,l,f,u+1);else if(s){let h=s.replace(/^\//,"");x(n,h,{stripQuotes:!0})&&f.push(c)}}}catch{}}async function oe(t,s){let l=[],f=t.lastIndexOf("/"),u,p;if(f===-1?(u=s.cwd,p=t):(u=t.slice(0,f)||"/",p=t.slice(f+1)),t.includes("**")){let a=[],n=t.split("**"),c=n[0].replace(/\/$/,"")||".",y=n[1]||"";return await ne(c,y,s,a),a.map(w=>({path:w}))}let m=s.fs.resolvePath(s.cwd,u);try{if(s.fs.readdirWithFileTypes){let a=await s.fs.readdirWithFileTypes(m);for(let n of a)if(x(n.name,p,{stripQuotes:!0})){let c=f===-1?n.name:`${u}/${n.name}`;l.push({path:c,isFile:n.isFile})}}else{let a=await s.fs.readdir(m);for(let n of a)if(x(n,p,{stripQuotes:!0})){let c=f===-1?n:`${u}/${n}`;l.push({path:c})}}}catch{}return l.sort((a,n)=>a.path.localeCompare(n.path))}async function L(t,s,l=[],f=[],u=[],p,m=0){if(m>=se)return[];let a=s.fs.resolvePath(s.cwd,t),n=[];try{let c,y;if(p!==void 0)c=p,y=!p;else{let h=await s.fs.stat(a);c=h.isFile,y=h.isDirectory}if(c){let h=t.split("/").pop()||t;return f.length>0&&f.some(d=>x(h,d,{stripQuotes:!0}))?[]:l.length>0&&!l.some(d=>x(h,d,{stripQuotes:!0}))?[]:[{path:t,isFile:!0}]}if(!y)return[];let w=t.split("/").pop()||t;if(u.length>0&&u.some(h=>x(w,h,{stripQuotes:!0})))return[];if(s.fs.readdirWithFileTypes){let h=await s.fs.readdirWithFileTypes(a);for(let d of h){if(d.name.startsWith("."))continue;let F=t==="."?d.name:`${t}/${d.name}`,C=await L(F,s,l,f,u,d.isFile,m+1);n.push(...C)}}else{let h=await s.fs.readdir(a);for(let d of h){if(d.startsWith("."))continue;let F=t==="."?d:`${t}/${d}`,C=await L(F,s,l,f,u,void 0,m+1);n.push(...C)}}}catch{}return n}var pe={name:"fgrep",async execute(t,s){return te.execute(["-F",...t],s)}},he={name:"egrep",async execute(t,s){return te.execute(["-E",...t],s)}},de={name:"grep",flags:[{flag:"-E",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-P",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-L",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-e",type:"value",valueHint:"pattern"}],stdinType:"text",needsArgs:!0},ge={name:"fgrep",flags:[],stdinType:"text",needsArgs:!0},me={name:"egrep",flags:[],stdinType:"text",needsArgs:!0};export{te as a,pe as b,he as c,de as d,ge as e,me as f};