File tree Expand file tree Collapse file tree 1 file changed +15
-18
lines changed
Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -10,33 +10,30 @@ program
1010
1111program . parse ( process . argv ) ;
1212
13- // options and path from commander.
14- const opts = program . opts ( ) ;
13+ const options = program . opts ( ) ;
1514
16- let paths = program . args ; // array of paths user typed
17- if ( paths . length === 0 ) {
18- paths = [ "." ] ;
19- }
15+ let paths = program . args ;
16+ if ( paths . length === 0 ) paths = [ "." ] ;
2017
2118for ( const directoryPath of paths ) {
22- let entries ;
19+ let fileNames ;
20+
2321 try {
24- entries = await fs . readdir ( directoryPath ) ;
22+ fileNames = await fs . readdir ( directoryPath ) ;
2523 } catch ( err ) {
2624 console . error ( `ls: cannot access '${ directoryPath } ': ${ err . message } ` ) ;
27- continue ; // move to next path if this one fails
25+ continue ;
2826 }
2927
30- if ( ! opts . allFiles ) {
31- entries = entries . filter ( ( name ) => ! name . startsWith ( "." ) ) ;
32- }
28+ fileNames = fileNames . filter (
29+ ( file ) => options . allFiles || ! file . startsWith ( "." ) ,
30+ ) ;
3331
34- if ( opts . onePerLine ) {
35- entries . forEach ( ( name ) => {
36- console . log ( name ) ;
37- } ) ;
32+ if ( options . onePerLine ) {
33+ for ( const file of fileNames ) {
34+ console . log ( file ) ;
35+ }
3836 } else {
39- //print files in one line if -1 is not used
40- console . log ( entries . join ( " " ) ) ;
37+ console . log ( fileNames . join ( " " ) ) ;
4138 }
4239}
You can’t perform that action at this time.
0 commit comments