import{a as m}from"./chunk-44UOCSGV.js";import{c}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";function h(s){let i=s.replace(/\//g,"-"),r=new Date(i);if(!Number.isNaN(r.getTime()))return r;let a=i.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(a){let[,o,l,d]=a;if(r=new Date(Number.parseInt(o,10),Number.parseInt(l,10)-1,Number.parseInt(d,10)),!Number.isNaN(r.getTime()))return r}let u=i.match(/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/);if(u){let[,o,l,d,t,e,f]=u;if(r=new Date(Number.parseInt(o,10),Number.parseInt(l,10)-1,Number.parseInt(d,10),Number.parseInt(t,10),Number.parseInt(e,10),Number.parseInt(f,10)),!Number.isNaN(r.getTime()))return r}return null}var b={name:"touch",async execute(s,i){let r=[],a=null,u=!1;for(let t=0;t<s.length;t++){let e=s[t];if(e==="--"){r.push(...s.slice(t+1));break}else if(e==="-d"||e==="--date"){if(t+1>=s.length)return{stdout:"",stderr:`touch: option requires an argument -- 'd'
`,exitCode:1};a=s[++t]}else if(e.startsWith("--date="))a=e.slice(7);else if(e==="-c"||e==="--no-create")u=!0;else if(e==="-a"||e==="-m"||e==="-r"||e==="-t")(e==="-r"||e==="-t")&&t++;else{if(e.startsWith("--"))return c("touch",e);if(e.startsWith("-")&&e.length>1){let f=!1;for(let n of e.slice(1))if(n==="c")u=!0;else if(!(n==="a"||n==="m"))if(n==="d"){if(t+1>=s.length)return{stdout:"",stderr:`touch: option requires an argument -- 'd'
`,exitCode:1};a=s[++t],f=!0;break}else if(n==="r"||n==="t"){t++,f=!0;break}else return c("touch",`-${n}`);if(f)continue}else r.push(e)}}if(r.length===0)return{stdout:"",stderr:`touch: missing file operand
`,exitCode:1};let o=null;if(a!==null&&(o=h(a),o===null))return{stdout:"",stderr:`touch: invalid date format '${a}'
`,exitCode:1};let l="",d=0;for(let t of r)try{let e=i.fs.resolvePath(i.cwd,t);if(!await i.fs.exists(e)){if(u)continue;await i.fs.writeFile(e,"")}let n=o??new Date;await i.fs.utimes(e,n,n)}catch(e){l+=`touch: cannot touch '${t}': ${m(e)}
`,d=1}return{stdout:"",stderr:l,exitCode:d}}};export{b as touchCommand};
