#!/usr/bin/env node
import{a as y}from"./chunk-JBABAK44.js";import{a as $}from"./chunk-4VDEBYW7.js";import{a as g,b as u}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var C={name:"mv",summary:"move (rename) files",usage:"mv [OPTION]... SOURCE... DEST",options:["-f, --force       do not prompt before overwriting","-n, --no-clobber  do not overwrite an existing file","-v, --verbose     explain what is being done","    --help        display this help and exit"]},P={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},O={name:"mv",async execute(m,t){if(u(m))return g(C);let s=y("mv",m,P);if(!s.ok)return s.error;let p=s.result.flags.force,d=s.result.flags.noClobber,w=s.result.flags.verbose,l=s.result.positional;if(d&&(p=!1),l.length<2)return{stdout:"",stderr:`mv: missing destination file operand
`,exitCode:1};let r=l.pop()??"",v=l,n=t.fs.resolvePath(t.cwd,r),h="",c="",b=0,a=!1;try{a=(await t.fs.stat(n)).isDirectory}catch{}if(v.length>1&&!a)return{stdout:"",stderr:`mv: target '${r}' is not a directory
`,exitCode:1};for(let e of v)try{let f=t.fs.resolvePath(t.cwd,e),o=n;if(a){let i=e.split("/").pop()||e;o=n==="/"?`/${i}`:`${n}/${i}`}if(d)try{await t.fs.stat(o);continue}catch{}if(await t.fs.mv(f,o),w){let i=a?`${r}/${e.split("/").pop()||e}`:r;h+=`renamed '${e}' -> '${i}'
`}}catch(f){let o=$(f);o.includes("ENOENT")||o.includes("no such file")?c+=`mv: cannot stat '${e}': No such file or directory
`:c+=`mv: cannot move '${e}': ${o}
`,b=1}return{stdout:h,stderr:c,exitCode:b}}};export{O as mvCommand};
