File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
implement-shell-tools/cat Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1- import { promises as fs } from "node:fs" ;
1+ import { readFileSync } from "node:fs" ;
22
3- async function cleanInput ( listOfFiles ) {
3+ function cleanInput ( listOfFiles ) {
44 let cleanLinesArr = [ ] ;
5+
56 for ( const file of listOfFiles ) {
6- const grabbedText = await fs . readFile ( file , "utf-8" ) ;
7+ const grabbedText = readFileSync ( file , "utf-8" ) ;
78 const splitLines = grabbedText . split ( "\n" ) ;
89 cleanLinesArr . push ( ...splitLines ) ;
910 }
1011 return cleanLinesArr ;
1112}
1213
14+ const args = process . argv . slice ( 2 ) ;
15+ let flag ;
16+ let restIsFiles ;
17+
18+ if ( args [ 0 ] && args [ 0 ] [ 0 ] === "-" ) {
19+ flag = args [ 0 ] ;
20+ restIsFiles = args . slice ( 1 ) ;
21+ } else {
22+ flag = null ;
23+ restIsFiles = args ;
24+ }
25+
1326function takeSpecifiedAction ( cleanLinesArr , flag ) {
1427 let countingOnlyFullLines = 1 ;
1528
@@ -32,3 +45,6 @@ function takeSpecifiedAction(cleanLinesArr, flag) {
3245 }
3346 }
3447}
48+
49+ const lines = cleanInput ( restIsFiles ) ;
50+ takeSpecifiedAction ( lines , flag ) ;
You can’t perform that action at this time.
0 commit comments