File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
implement-shell-tools/cat Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -14,22 +14,20 @@ const number = program.opts().n;
1414const nonEmptyLine = program . opts ( ) . b ;
1515
1616let lineNumber = 1 ;
17-
17+
1818for ( const path of paths ) {
1919 try {
2020 const read = await fs . readFile ( path , "utf-8" ) ;
2121 const lines = read . split ( "\n" ) ;
22+
23+ function printNumLine ( line ) {
24+ console . log ( `${ String ( lineNumber ) . padStart ( 6 , " " ) } ${ line } ` ) ;
25+ lineNumber ++ ;
26+ }
27+
2228 for ( let i of lines ) {
23- if ( number ) {
24- console . log ( `${ String ( lineNumber ) . padStart ( 6 , " " ) } ${ i } ` ) ;
25- lineNumber ++ ;
26- } else if ( nonEmptyLine ) {
27- if ( i . trim ( ) !== "" ) {
28- console . log ( `${ String ( lineNumber ) . padStart ( 6 , " " ) } ${ i } ` ) ;
29- lineNumber ++ ;
30- } else {
31- console . log ( i ) ;
32- }
29+ if ( number || ( nonEmptyLine && i . trim ( ) !== "" ) ) {
30+ printNumLine ( i ) ;
3331 } else {
3432 console . log ( i ) ;
3533 }
You can’t perform that action at this time.
0 commit comments