-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathmy-ls.js
More file actions
executable file
·41 lines (29 loc) · 739 Bytes
/
Copy pathmy-ls.js
File metadata and controls
executable file
·41 lines (29 loc) · 739 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
37
38
39
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
function parseArgs(args) {
let showAll = false;
let targetDir = ".";
for (const arg of args) {
if (arg === "-a") {
showAll = true;
} else if (!arg.startsWith("-")) {
targetDir = arg;
}
}
return { showAll, targetDir };
}
function listDirectory(dirPath, showAll) {
let files = fs.readdirSync(dirPath);
if (!showAll) {
files = files.filter(file => !file.startsWith("."));
}
return files.sort();
}
function main() {
const args = process.argv.slice(2);
const { showAll, targetDir } = parseArgs(args);
const files = listDirectory(targetDir, showAll);
console.log(files.join("\n"));
}
main();