import{n as e,t}from"./chunk-A5O5YHGN-DApqA6Ow.mjs";import{t as n}from"./chunk-IPJHKYVM-CUKythEA.mjs";import{n as r,r as i,t as a}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as o}from"./chunk-3ZUFRYJ4-Bv1jGN68.mjs";var s={name:`timeout`,summary:`run a command with a time limit`,usage:`timeout [OPTION] DURATION COMMAND [ARG]...`,description:`Start COMMAND, and kill it if still running after DURATION.

DURATION is a number with optional suffix:
  s - seconds (default)
  m - minutes
  h - hours
  d - days`,options:[`-k, --kill-after=DURATION  send KILL signal after DURATION if still running`,`-s, --signal=SIGNAL        specify signal to send (default: TERM)`,`    --preserve-status      exit with same status as COMMAND, even on timeout`,`    --foreground           run command in foreground`,`    --help                 display this help and exit`]},c={name:`timeout`,async execute(c,l){if(a(c))return i(s);let u=0;for(let e=0;e<c.length;e++){let t=c[e];if(t===`--preserve-status`)u=e+1;else if(t===`--foreground`)u=e+1;else if(t===`-k`||t===`--kill-after`)e++,u=e+1;else if(t.startsWith(`--kill-after=`))u=e+1;else if(t===`-s`||t===`--signal`)e++,u=e+1;else if(t.startsWith(`--signal=`))u=e+1;else{if(t.startsWith(`--`)&&t!==`--`)return r(`timeout`,t);if(t.startsWith(`-`)&&t.length>1&&t!==`--`)if(t.startsWith(`-k`))u=e+1;else if(t.startsWith(`-s`))u=e+1;else return r(`timeout`,t);else{u=e;break}}}let d=c.slice(u);if(d.length===0)return{stdout:``,stderr:`timeout: missing operand
`,exitCode:1};let f=d[0],p=o(f);if(p===null)return{stdout:``,stderr:`timeout: invalid time interval '${f}'
`,exitCode:1};let m=d.slice(1);if(m.length===0)return{stdout:``,stderr:`timeout: missing operand
`,exitCode:1};if(!l.exec)return{stdout:``,stderr:`timeout: exec not available
`,exitCode:1};let h=new AbortController,g;try{let e=new Promise(e=>{g=t(()=>{h.abort(),e({timedOut:!0})},p)}),r=l.exec(n([m[0]]),{cwd:l.cwd,signal:h.signal,stdin:l.stdin,args:m.slice(1)}).then(e=>({timedOut:!1,result:e})),i=await Promise.race([e,r]);return i.timedOut?{stdout:``,stderr:``,exitCode:124}:i.result}finally{g!==void 0&&e(g)}}},l={name:`timeout`,flags:[{flag:`-k`,type:`value`,valueHint:`string`},{flag:`-s`,type:`value`,valueHint:`string`},{flag:`--preserve-status`,type:`boolean`},{flag:`--foreground`,type:`boolean`}],needsArgs:!0,minArgs:2};export{c as n,l as t};
//# sourceMappingURL=chunk-YTNYSM6T-DpkSVTln.mjs.map