-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathmyLs.js
More file actions
36 lines (28 loc) · 692 Bytes
/
myLs.js
File metadata and controls
36 lines (28 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { program } from "commander";
import { promises as fs } from "node:fs";
import process from "node:process";
program
.name("myLs")
.description("my ls clone")
.option("-1", "one entry per line")
.option("-a", "show hidden files")
.argument("[paths...]", "file or directory paths");
program.parse();
const opts = program.opts();
let paths = program.args;
if (paths.length === 0) {
paths = ["."];
}
for (const path of paths) {
const entries = await fs.readdir(path);
for (const file of entries) {
if (!opts.a && file.startsWith(".")) {
continue;
}
if (opts["1"]) {
console.log(file);
} else {
console.log(file + " ");
}
}
}