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