11import { program } from "commander" ;
2- import fs from "node:fs" ;
2+ import fs , { chownSync } from "node:fs" ;
33import process from "node:process" ;
44
55program
@@ -13,10 +13,10 @@ program
1313program . parse ( ) ;
1414
1515const options = program . opts ( ) ;
16- const files = program . args ;
16+ const paths = program . args ;
1717
1818console . log ( options ) ;
19- console . log ( files ) ;
19+ console . log ( paths ) ;
2020
2121// if no -lwc flags are supplied, wc prints
2222// lines, words, bytes of each file
@@ -27,7 +27,24 @@ if (Object.keys(options).length === 0) {
2727}
2828
2929/*
30- array of objects with data [{l: 2, w: 12: c: 123, file: 'sample-files/1.txt}, ...]
31- For each item, create a temp string
32- If options.l, append to temp string the w value
30+ for each path:
31+ if path is not a directory, show error message
32+ else:
33+ create a temporary array
34+ if l in options:
35+ push line count to temp arr
36+ if w in options:
37+ push word count into temp arr
38+ if c in options:
39+ push byte count into data
40+
41+ join the array with path and print
3342*/
43+
44+ for ( const path of paths ) {
45+ if ( fs . statSync ( path ) . isDirectory ( ) ) {
46+ console . log ( `wc: ${ path } : read: Is a directory` ) ;
47+ } else {
48+ console . log ( `${ path } is a file` ) ;
49+ }
50+ }
0 commit comments