File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ const fs = require ( 'fs' ) ;
4+ const path = require ( 'path' ) ;
5+
6+ function listFiles ( directory , options ) {
7+ try {
8+ const files = fs . readdirSync ( directory , { withFileTypes : true } ) ;
9+
10+ files . forEach ( ( file ) => {
11+ if ( ! options . all && file . name . startsWith ( '.' ) ) {
12+ return ; // Skip hidden files unless -a is specified
13+ }
14+ console . log ( file . name ) ;
15+ } ) ;
16+ } catch ( err ) {
17+ console . error ( `ls: cannot access '${ directory } ': No such file or directory` ) ;
18+ }
19+ }
20+
21+ function main ( ) {
22+ const args = process . argv . slice ( 2 ) ;
23+ const options = {
24+ all : false ,
25+ } ;
26+
27+ let directories = [ '.' ] ;
28+
29+ args . forEach ( ( arg ) => {
30+ if ( arg === '-1' ) {
31+ // -1 is the default behavior, so no action needed
32+ } else if ( arg === '-a' ) {
33+ options . all = true ;
34+ } else {
35+ directories = [ arg ] ;
36+ }
37+ } ) ;
38+
39+ directories . forEach ( ( directory ) => {
40+ listFiles ( directory , options ) ;
41+ } ) ;
42+ }
43+
44+ main ( ) ;
You can’t perform that action at this time.
0 commit comments