File tree Expand file tree Collapse file tree
implement-shell-tools/cat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,23 +2,32 @@ const fs = require("fs");
22
33const args = process . argv . slice ( 2 ) ;
44
5- const numberLines = args [ 0 ] === "-n" ;
5+ const numberAll = args [ 0 ] === "-n" ;
6+ const numberNonBlank = args [ 0 ] === "-b" ;
67
7- const files = numberLines ? args . slice ( 1 ) : args ;
8+ const files = ( numberAll || numberNonBlank )
9+ ? args . slice ( 1 )
10+ : args ;
811
912let lineNumber = 1 ;
1013
1114for ( const file of files ) {
1215 const content = fs . readFileSync ( file , "utf8" ) ;
13-
1416 const lines = content . split ( "\n" ) ;
1517
1618 for ( const line of lines ) {
17- if ( numberLines ) {
19+
20+ if ( numberAll ) {
1821 console . log ( `${ String ( lineNumber ) . padStart ( 6 ) } \t${ line } ` ) ;
1922 lineNumber ++ ;
23+
24+ } else if ( numberNonBlank && line !== "" ) {
25+ console . log ( `${ String ( lineNumber ) . padStart ( 6 ) } \t${ line } ` ) ;
26+ lineNumber ++ ;
27+
2028 } else {
2129 console . log ( line ) ;
2230 }
31+
2332 }
2433}
You can’t perform that action at this time.
0 commit comments