88 . description ( "Counts lines, words or characters in a file (or all files) inside a directory" )
99 . option ( "-l, --line" , "The number of lines in each file" )
1010 . option ( "-w, --word" , "The number of words in each file" )
11+ . option ( "-c, --character" , "The number of characters in each file" )
1112 . argument ( "<path...>" , "The file path to process" ) ;
1213
1314program . parse ( ) ;
@@ -44,8 +45,10 @@ if (pathInfo.isFile()) {
4445 const stats = counter ( content ) ;
4546 if ( options . line ) {
4647 console . log ( `${ stats . lines } ${ path } ` ) ;
48+ } else if ( options . word ) {
49+ console . log ( `${ stats . words } ${ path } ` ) ;
4750 } else {
48- console . log ( `${ stats . lines } ${ stats . words } ${ stats . characters } ${ path } ` ) ;
51+ console . log ( `${ stats . characters } ${ path } ` ) ;
4952 }
5053
5154 totalLines += stats . lines ;
@@ -62,8 +65,10 @@ if (pathInfo.isFile()) {
6265
6366 if ( options . line ) {
6467 console . log ( `${ stats . lines } ${ filePath } ` ) ;
68+ } else if ( options . word ) {
69+ console . log ( `${ stats . words } ${ filePath } ` ) ;
6570 } else {
66- console . log ( `${ stats . lines } ${ stats . words } ${ stats . characters } ${ filePath } ` ) ;
71+ console . log ( `${ stats . characters } ${ filePath } ` ) ;
6772 }
6873
6974 totalLines += stats . lines ;
@@ -78,7 +83,9 @@ if (pathInfo.isFile()) {
7883if ( fileCount > 1 ) {
7984 if ( options . line ) {
8085 console . log ( `${ totalLines } total` ) ;
86+ } else if ( options . word ) {
87+ console . log ( `${ totalWords } total` ) ;
8188 } else {
82- console . log ( `${ totalLines } ${ totalWords } ${ totalCharacters } total` ) ;
89+ console . log ( `${ totalCharacters } total` ) ;
8390 }
8491}
0 commit comments