import{t as e}from"./chunk-44UOCSGV-BZ6LfyW2.mjs";import{r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as r}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var i={name:`cp`,summary:`copy files and directories`,usage:`cp [OPTION]... SOURCE... DEST`,options:[`-r, -R, --recursive  copy directories recursively`,`-n, --no-clobber     do not overwrite an existing file`,`-p, --preserve       preserve file attributes`,`-v, --verbose        explain what is being done`,`    --help           display this help and exit`]},a={recursive:{short:`r`,long:`recursive`,type:`boolean`},recursiveUpper:{short:`R`,type:`boolean`},noClobber:{short:`n`,long:`no-clobber`,type:`boolean`},preserve:{short:`p`,long:`preserve`,type:`boolean`},verbose:{short:`v`,long:`verbose`,type:`boolean`}},o={name:`cp`,async execute(o,s){if(n(o))return t(i);let c=r(`cp`,o,a);if(!c.ok)return c.error;let l=c.result.flags.recursive||c.result.flags.recursiveUpper,u=c.result.flags.noClobber;c.result.flags.preserve;let d=c.result.flags.verbose,f=c.result.positional;if(f.length<2)return{stdout:``,stderr:`cp: missing destination file operand
`,exitCode:1};let p=f.pop()??``,m=f,h=s.fs.resolvePath(s.cwd,p),g=``,_=``,v=0,y=!1;try{y=(await s.fs.stat(h)).isDirectory}catch{}if(m.length>1&&!y)return{stdout:``,stderr:`cp: target '${p}' is not a directory
`,exitCode:1};for(let t of m)try{let e=s.fs.resolvePath(s.cwd,t),n=await s.fs.stat(e),r=h;if(y){let e=t.split(`/`).pop()||t;r=h===`/`?`/${e}`:`${h}/${e}`}if(n.isDirectory&&!l){_+=`cp: -r not specified; omitting directory '${t}'
`,v=1;continue}if(u)try{await s.fs.stat(r);continue}catch{}await s.fs.cp(e,r,{recursive:l}),d&&(g+=`'${t}' -> '${r}'
`)}catch(n){let r=e(n);r.includes(`ENOENT`)||r.includes(`no such file`)?_+=`cp: cannot stat '${t}': No such file or directory
`:_+=`cp: cannot copy '${t}': ${r}
`,v=1}return{stdout:g,stderr:_,exitCode:v}}},s={name:`cp`,flags:[{flag:`-r`,type:`boolean`},{flag:`-R`,type:`boolean`},{flag:`-n`,type:`boolean`},{flag:`-p`,type:`boolean`},{flag:`-v`,type:`boolean`}],needsArgs:!0,minArgs:2};export{s as n,o as t};
//# sourceMappingURL=chunk-NUYSJFDK-BH2DjyxF.mjs.map