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 @@ -4,16 +4,21 @@ const args = process.argv.slice(2);
44
55const numberLines = args [ 0 ] === "-n" ;
66
7- const filename = numberLines ? args [ 1 ] : args [ 0 ] ;
7+ const files = numberLines ? args . slice ( 1 ) : args ;
88
9- const content = fs . readFileSync ( filename , "utf8" ) ;
9+ let lineNumber = 1 ;
1010
11- const lines = content . split ( "\n" ) ;
11+ for ( const file of files ) {
12+ const content = fs . readFileSync ( file , "utf8" ) ;
1213
13- if ( numberLines ) {
14- lines . forEach ( ( line , index ) => {
15- console . log ( `${ String ( index + 1 ) . padStart ( 6 ) } \t${ line } ` ) ;
16- } ) ;
17- } else {
18- process . stdout . write ( content ) ;
14+ const lines = content . split ( "\n" ) ;
15+
16+ for ( const line of lines ) {
17+ if ( numberLines ) {
18+ console . log ( `${ String ( lineNumber ) . padStart ( 6 ) } \t${ line } ` ) ;
19+ lineNumber ++ ;
20+ } else {
21+ console . log ( line ) ;
22+ }
23+ }
1924}
You can’t perform that action at this time.
0 commit comments