import{t as e}from"./chunk-44UOCSGV-BZ6LfyW2.mjs";import{t}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var n=`Usage: rmdir [-pv] DIRECTORY...
Remove empty directories.

Options:
  -p, --parents   Remove DIRECTORY and its ancestors
  -v, --verbose   Output a diagnostic for every directory processed`,r={parents:{short:`p`,long:`parents`,type:`boolean`},verbose:{short:`v`,long:`verbose`,type:`boolean`},help:{long:`help`,type:`boolean`}},i={name:`rmdir`,async execute(e,i){let o=t(`rmdir`,e,r);if(!o.ok)return o.error;if(o.result.flags.help)return{stdout:`${n}
`,stderr:``,exitCode:0};let s=o.result.flags.parents,c=o.result.flags.verbose,l=o.result.positional;if(l.length===0)return{stdout:``,stderr:`rmdir: missing operand
`,exitCode:1};let u=``,d=``,f=0;for(let e of l){let t=await a(i,e,s,c);u+=t.stdout,d+=t.stderr,t.exitCode!==0&&(f=t.exitCode)}return{stdout:u,stderr:d,exitCode:f}}};async function a(e,t,n,r){let i=``,a=``,c=e.fs.resolvePath(e.cwd,t),l=await o(e,c,t,r);if(i+=l.stdout,a+=l.stderr,l.exitCode!==0)return{stdout:i,stderr:a,exitCode:l.exitCode};if(n){let n=c,a=t;for(;;){let t=s(n),c=s(a);if(t===n||t===`/`||t===`.`||c===`.`||c===``)break;let l=await o(e,t,c,r);if(i+=l.stdout,l.exitCode!==0)break;n=t,a=c}}return{stdout:i,stderr:a,exitCode:0}}async function o(t,n,r,i){try{if(!await t.fs.exists(n))return{stdout:``,stderr:`rmdir: failed to remove '${r}': No such file or directory
`,exitCode:1};if(!(await t.fs.stat(n)).isDirectory)return{stdout:``,stderr:`rmdir: failed to remove '${r}': Not a directory
`,exitCode:1};if((await t.fs.readdir(n)).length>0)return{stdout:``,stderr:`rmdir: failed to remove '${r}': Directory not empty
`,exitCode:1};await t.fs.rm(n,{recursive:!1,force:!1});let e=``;return i&&(e=`rmdir: removing directory, '${r}'
`),{stdout:e,stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`rmdir: failed to remove '${r}': ${e(t)}
`,exitCode:1}}}function s(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n===-1?`.`:n===0?`/`:t.substring(0,n)}var c={name:`rmdir`,flags:[{flag:`-p`,type:`boolean`},{flag:`-v`,type:`boolean`}],needsArgs:!0};export{i as n,c as t};
//# sourceMappingURL=chunk-OCS6LSEM-Bcx6uxmm.mjs.map