#!/usr/bin/env node
import{a as m}from"./chunk-JBABAK44.js";import{a as $}from"./chunk-4VDEBYW7.js";import{a as g,b as y}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var D={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"]},E={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"}},R={name:"cp",async execute(f,e){if(y(f))return g(D);let t=m("cp",f,E);if(!t.ok)return t.error;let u=t.result.flags.recursive||t.result.flags.recursiveUpper,w=t.result.flags.noClobber,C=t.result.flags.preserve,P=t.result.flags.verbose,a=t.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand
`,exitCode:1};let d=a.pop()??"",h=a,o=e.fs.resolvePath(e.cwd,d),v="",n="",l=0,p=!1;try{p=(await e.fs.stat(o)).isDirectory}catch{}if(h.length>1&&!p)return{stdout:"",stderr:`cp: target '${d}' is not a directory
`,exitCode:1};for(let r of h)try{let i=e.fs.resolvePath(e.cwd,r),s=await e.fs.stat(i),c=o;if(p){let b=r.split("/").pop()||r;c=o==="/"?`/${b}`:`${o}/${b}`}if(s.isDirectory&&!u){n+=`cp: -r not specified; omitting directory '${r}'
`,l=1;continue}if(w)try{await e.fs.stat(c);continue}catch{}await e.fs.cp(i,c,{recursive:u}),P&&(v+=`'${r}' -> '${c}'
`)}catch(i){let s=$(i);s.includes("ENOENT")||s.includes("no such file")?n+=`cp: cannot stat '${r}': No such file or directory
`:n+=`cp: cannot copy '${r}': ${s}
`,l=1}return{stdout:v,stderr:n,exitCode:l}}};export{R as cpCommand};
