import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var r={name:`tree`,summary:`list contents of directories in a tree-like format`,usage:`tree [OPTION]... [DIRECTORY]...`,options:[`-a          include hidden files`,`-d          list directories only`,`-L LEVEL    limit depth of directory tree`,`-f          print full path prefix for each file`,`    --help  display this help and exit`]},i={showHidden:{short:`a`,type:`boolean`},directoriesOnly:{short:`d`,type:`boolean`},fullPath:{short:`f`,type:`boolean`},maxDepth:{short:`L`,type:`number`}},a={name:`tree`,async execute(a,s){if(t(a))return e(r);let c=n(`tree`,a,i);if(!c.ok)return c.error;let l={showHidden:c.result.flags.showHidden,directoriesOnly:c.result.flags.directoriesOnly,maxDepth:c.result.flags.maxDepth??null,fullPath:c.result.flags.fullPath},u=c.result.positional;u.length===0&&u.push(`.`);let d=``,f=``,p=0,m=0;for(let e of u){let t=await o(s,e,l,``,0);d+=t.output,f+=t.stderr,p+=t.dirCount,m+=t.fileCount}return d+=`
${p} director${p===1?`y`:`ies`}`,l.directoriesOnly||(d+=`, ${m} file${m===1?``:`s`}`),d+=`
`,{stdout:d,stderr:f,exitCode:f?1:0}}};async function o(e,t,n,r,i){let a={output:``,stderr:``,dirCount:0,fileCount:0},o=e.fs.resolvePath(e.cwd,t);try{if(!(await e.fs.stat(o)).isDirectory)return a.output=`${t}
`,a.fileCount=1,a}catch{return a.stderr=`tree: ${t}: No such file or directory
`,a}if(a.output=`${t}
`,n.maxDepth!==null&&i>=n.maxDepth)return a;try{let t=[];if(e.fs.readdirWithFileTypes)t=(await e.fs.readdirWithFileTypes(o)).map(e=>({name:e.name,isDirectory:e.isDirectory}));else{let n=await e.fs.readdir(o);for(let r=0;r<n.length;r+=100){let i=n.slice(r,r+100),a=await Promise.all(i.map(async t=>{let n=o===`/`?`/${t}`:`${o}/${t}`;try{return{name:t,isDirectory:(await e.fs.stat(n)).isDirectory}}catch{return null}}));t.push(...a.filter(e=>e!==null))}}let c=t.filter(e=>!(!n.showHidden&&e.name.startsWith(`.`)||n.directoriesOnly&&!e.isDirectory));c.sort((e,t)=>e.name.localeCompare(t.name));for(let t=0;t<c.length;t++){let l=c[t],u=o===`/`?`/${l.name}`:`${o}/${l.name}`,d=t===c.length-1,f=d?"`-- ":`|-- `,p=r+(d?`    `:`|   `);if(l.isDirectory){a.dirCount++;let t=n.fullPath?u:l.name;if(a.output+=`${r+f+t}
`,n.maxDepth===null||i+1<n.maxDepth){let t=await s(e,u,n,p,i+1);a.output+=t.output,a.dirCount+=t.dirCount,a.fileCount+=t.fileCount}}else{a.fileCount++;let e=n.fullPath?u:l.name;a.output+=`${r+f+e}
`}}}catch{a.stderr=`tree: ${t}: Permission denied
`}return a}async function s(e,t,n,r,i){let a={output:``,stderr:``,dirCount:0,fileCount:0};if(n.maxDepth!==null&&i>=n.maxDepth)return a;try{let o=[];if(e.fs.readdirWithFileTypes)o=(await e.fs.readdirWithFileTypes(t)).map(e=>({name:e.name,isDirectory:e.isDirectory}));else{let n=await e.fs.readdir(t);for(let r=0;r<n.length;r+=100){let i=n.slice(r,r+100),a=await Promise.all(i.map(async n=>{let r=t===`/`?`/${n}`:`${t}/${n}`;try{return{name:n,isDirectory:(await e.fs.stat(r)).isDirectory}}catch{return null}}));o.push(...a.filter(e=>e!==null))}}let c=o.filter(e=>!(!n.showHidden&&e.name.startsWith(`.`)||n.directoriesOnly&&!e.isDirectory));c.sort((e,t)=>e.name.localeCompare(t.name));for(let o=0;o<c.length;o++){let l=c[o],u=t===`/`?`/${l.name}`:`${t}/${l.name}`,d=o===c.length-1,f=d?"`-- ":`|-- `,p=r+(d?`    `:`|   `);if(l.isDirectory){a.dirCount++;let t=n.fullPath?u:l.name;a.output+=`${r+f+t}
`;let o=await s(e,u,n,p,i+1);a.output+=o.output,a.dirCount+=o.dirCount,a.fileCount+=o.fileCount}else{a.fileCount++;let e=n.fullPath?u:l.name;a.output+=`${r+f+e}
`}}}catch{}return a}var c={name:`tree`,flags:[{flag:`-a`,type:`boolean`},{flag:`-d`,type:`boolean`},{flag:`-f`,type:`boolean`},{flag:`-L`,type:`value`,valueHint:`number`}],needsFiles:!0};export{a as n,c as t};
//# sourceMappingURL=chunk-XVDPCNWR-CkzIJQaO.mjs.map