import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";var r={name:`nl`,summary:`number lines of files`,usage:`nl [OPTION]... [FILE]...`,description:`Write each FILE to standard output, with line numbers added. If no FILE is specified, standard input is read.`,options:[`-b STYLE     Body numbering style: a (all), t (non-empty), n (none)`,`-n FORMAT    Number format: ln (left), rn (right), rz (right zeros)`,`-w WIDTH     Number width (default: 6)`,`-s SEP       Separator after number (default: TAB)`,`-v START     Starting line number (default: 1)`,`-i INCR      Line number increment (default: 1)`],examples:[`nl file.txt              # Number non-empty lines`,`nl -ba file.txt          # Number all lines`,`nl -n rz -w 3 file.txt   # Right-justified with zeros`,`nl -s ': ' file.txt      # Use ': ' as separator`]};function i(e,t,n){let r=String(e);switch(t){case`ln`:return r.padEnd(n);case`rn`:return r.padStart(n);case`rz`:return r.padStart(n,`0`);default:return t}}function a(e,t){switch(t){case`a`:return!0;case`t`:return e.trim().length>0;case`n`:return!1;default:return t}}function o(e,t,n){if(e===``)return{output:``,nextNumber:n};let r=e.split(`
`),o=[],s=n,c=e.endsWith(`
`)&&r[r.length-1]===``;c&&r.pop();for(let e of r)if(a(e,t.bodyStyle)){let n=i(s,t.numberFormat,t.width);o.push(`${n}${t.separator}${e}`),s+=t.increment}else{let n=` `.repeat(t.width);o.push(`${n}${t.separator}${e}`)}return{output:o.join(`
`)+(c?`
`:``),nextNumber:s}}var s={name:`nl`,execute:async(i,a)=>{if(n(i))return t(r);let s={bodyStyle:`t`,numberFormat:`rn`,width:6,separator:`	`,startNumber:1,increment:1},c=[],l=0;for(;l<i.length;){let t=i[l];if(t===`-b`&&l+1<i.length){let e=i[l+1];if(e!==`a`&&e!==`t`&&e!==`n`)return{exitCode:1,stdout:``,stderr:`nl: invalid body numbering style: '${e}'
`};s.bodyStyle=e,l+=2}else if(t.startsWith(`-b`)){let e=t.slice(2);if(e!==`a`&&e!==`t`&&e!==`n`)return{exitCode:1,stdout:``,stderr:`nl: invalid body numbering style: '${e}'
`};s.bodyStyle=e,l++}else if(t===`-n`&&l+1<i.length){let e=i[l+1];if(e!==`ln`&&e!==`rn`&&e!==`rz`)return{exitCode:1,stdout:``,stderr:`nl: invalid line numbering format: '${e}'
`};s.numberFormat=e,l+=2}else if(t.startsWith(`-n`)){let e=t.slice(2);if(e!==`ln`&&e!==`rn`&&e!==`rz`)return{exitCode:1,stdout:``,stderr:`nl: invalid line numbering format: '${e}'
`};s.numberFormat=e,l++}else if(t===`-w`&&l+1<i.length){let e=parseInt(i[l+1],10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`nl: invalid line number field width: '${i[l+1]}'
`};s.width=e,l+=2}else if(t.startsWith(`-w`)){let e=parseInt(t.slice(2),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`nl: invalid line number field width: '${t.slice(2)}'
`};s.width=e,l++}else if(t===`-s`&&l+1<i.length)s.separator=i[l+1],l+=2;else if(t.startsWith(`-s`))s.separator=t.slice(2),l++;else if(t===`-v`&&l+1<i.length){let e=parseInt(i[l+1],10);if(Number.isNaN(e))return{exitCode:1,stdout:``,stderr:`nl: invalid starting line number: '${i[l+1]}'
`};s.startNumber=e,l+=2}else if(t.startsWith(`-v`)){let e=parseInt(t.slice(2),10);if(Number.isNaN(e))return{exitCode:1,stdout:``,stderr:`nl: invalid starting line number: '${t.slice(2)}'
`};s.startNumber=e,l++}else if(t===`-i`&&l+1<i.length){let e=parseInt(i[l+1],10);if(Number.isNaN(e))return{exitCode:1,stdout:``,stderr:`nl: invalid line number increment: '${i[l+1]}'
`};s.increment=e,l+=2}else if(t.startsWith(`-i`)){let e=parseInt(t.slice(2),10);if(Number.isNaN(e))return{exitCode:1,stdout:``,stderr:`nl: invalid line number increment: '${t.slice(2)}'
`};s.increment=e,l++}else if(t===`--`){c.push(...i.slice(l+1));break}else{if(t.startsWith(`-`)&&t!==`-`)return e(`nl`,t);c.push(t),l++}}let u=``,d=s.startNumber;if(c.length===0)u=o(a.stdin??``,s,d).output;else for(let e of c){let t=a.fs.resolvePath(a.cwd,e),n=await a.fs.readFile(t);if(n===null)return{exitCode:1,stdout:u,stderr:`nl: ${e}: No such file or directory
`};let r=o(n,s,d);u+=r.output,d=r.nextNumber}return{exitCode:0,stdout:u,stderr:``}}},c={name:`nl`,flags:[{flag:`-b`,type:`value`,valueHint:`string`},{flag:`-n`,type:`value`,valueHint:`string`},{flag:`-w`,type:`value`,valueHint:`number`},{flag:`-s`,type:`value`,valueHint:`string`},{flag:`-v`,type:`value`,valueHint:`number`},{flag:`-i`,type:`value`,valueHint:`number`}],stdinType:`text`,needsFiles:!0};export{s as n,c as t};
//# sourceMappingURL=chunk-F23WWYKW-DLeNVzzD.mjs.map