11import { program } from "commander" ;
22import { promises as fs } from "node:fs" ;
3- import process from "node:process" ;
43
54program
6- . name ( "myLs " )
7- . description ( "my ls clone" )
5+ . name ( "myWc " )
6+ . description ( "my wc clone" )
87 . option ( "-l" , "line count" )
98 . option ( "-w" , "words count" )
109 . option ( "-c" , "character count" )
@@ -26,7 +25,6 @@ let totalWords = 0;
2625if ( opts . l ) {
2726 for ( const file of files ) {
2827 const content = await fs . readFile ( file , "utf-8" ) ;
29- console . log ( content ) ;
3028 const lineCount = content . split ( "\n" ) . length ;
3129
3230 totalLines += lineCount ;
@@ -36,7 +34,6 @@ if (opts.l) {
3634if ( opts . w ) {
3735 for ( const file of files ) {
3836 const content = await fs . readFile ( file , "utf-8" ) ;
39- console . log ( content ) ;
4037
4138 const wordCount = content . trim ( ) . split ( / \s + / ) . length ;
4239 totalWords += wordCount ;
@@ -49,10 +46,7 @@ if (opts.c) {
4946 const content = await fs . readFile ( file , "utf-8" ) ;
5047
5148 totalChars += content . trim ( ) . length ;
52- // const charList = content.trim().split(/\s+/);
53- // for (const char of charList) {
54- // totalChars += char.length;
55- // }
49+
5650 }
5751 console . log ( "Total characters:" , totalChars ) ;
5852}
0 commit comments