-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathls.mjs
More file actions
25 lines (21 loc) · 581 Bytes
/
ls.mjs
File metadata and controls
25 lines (21 loc) · 581 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
import { promises as fs } from "node:fs";
import { program } from "commander";
program
.name("ls ")
.description("ls implementation")
.argument("[path]", "The path to process")
.option("-1, --one-per-line", "one file per line")
.option("-a", "show hidden files");
program.parse();
const path = program.args[0] || ".";
const options = program.opts();
try {
const files = await fs.readdir(path);
for(const file of files)
{
if(!options.a && file.startsWith("."))continue;
console.log(file);
}
} catch (error) {
console.error(error.message);
}