forked from CodeYourFuture/Module-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.js
More file actions
28 lines (22 loc) · 666 Bytes
/
Copy pathls.js
File metadata and controls
28 lines (22 loc) · 666 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
import { program } from "commander";
import { promises as fs } from "node:fs";
program
.name("ls")
.description("List directory contents")
.option("-a, --all", "show hidden files")
.option("-1, --one-per-line", "display one file per line")
.argument("[path]", "directory to list", ".");
program.parse();
const options = program.opts();
const path = program.args[0] || ".";
const files = await fs.readdir(path);
const filteredFiles = files.filter((file) => {
return options.all || !file.startsWith(".");
});
if (options.onePerLine) {
for (const file of filteredFiles) {
console.log(file);
}
} else {
console.log(filteredFiles.join(" "));
}