import{r as e}from"./chunk-CWQS3NFK-BkE4vqrf.mjs";import{t}from"./chunk-IPJHKYVM-CUKythEA.mjs";import{r as n}from"./chunk-OJDRYQWQ-CmrD0Dg2.mjs";import{n as r}from"./chunk-3THT3N7L-B1WzJUh4.mjs";var i={name:`time`,async execute(i,o){let s=`%e %M`,c=null,l=!1,u=!1,d=0;for(;d<i.length;){let e=i[d];if(e===`-f`||e===`--format`){if(d++,d>=i.length)return{stdout:``,stderr:`time: missing argument to '-f'
`,exitCode:1};s=i[d],d++}else if(e===`-o`||e===`--output`){if(d++,d>=i.length)return{stdout:``,stderr:`time: missing argument to '-o'
`,exitCode:1};c=i[d],d++}else if(e===`-a`||e===`--append`)l=!0,d++;else if(e===`-v`||e===`--verbose`)s=`Command being timed: %C
Elapsed (wall clock) time: %e seconds
Maximum resident set size (kbytes): %M`,d++;else if(e===`-p`||e===`--portability`)u=!0,d++;else if(e===`--`){d++;break}else if(e.startsWith(`-`))d++;else break}let f=i.slice(d);if(f.length===0)return{stdout:``,stderr:``,exitCode:0};let p=e(),m=f.join(` `),h;try{if(!o.exec)return{stdout:``,stderr:`time: exec not available
`,exitCode:1};h=await o.exec(t([f[0]]),{env:n(o.env),cwd:o.cwd,stdin:o.stdin,signal:o.signal,args:f.slice(1)})}catch(e){h={stdout:``,stderr:`time: ${r(e.message)}
`,exitCode:127}}let g=(e()-p)/1e3,_;if(u?_=`real ${g.toFixed(2)}
user 0.00
sys 0.00
`:(_=s.replace(/%e/g,g.toFixed(2)).replace(/%E/g,a(g)).replace(/%M/g,`0`).replace(/%S/g,`0.00`).replace(/%U/g,`0.00`).replace(/%P/g,`0%`).replace(/%C/g,m),_.endsWith(`
`)||(_+=`
`)),c)try{let e=o.fs.resolvePath(o.cwd,c);if(l&&await o.fs.exists(e)){let t=await o.fs.readFile(e);await o.fs.writeFile(e,t+_)}else await o.fs.writeFile(e,_)}catch(e){let t=r(e.message);return{stdout:h.stdout,stderr:h.stderr+`time: cannot write to '${c}': ${t}
`,exitCode:h.exitCode}}else h={...h,stderr:h.stderr+_};return h}};function a(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toFixed(2).padStart(5,`0`)}`:`${n}:${r.toFixed(2).padStart(5,`0`)}`}var o={name:`time`,flags:[{flag:`-p`,type:`boolean`}],needsArgs:!0};export{i as n,o as t};
//# sourceMappingURL=chunk-Z6LRHWXI-EsbeaQ3V.mjs.map