We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8020365 commit 85bb502Copy full SHA for 85bb502
1 file changed
implement-shell-tools/ls/ls.mjs
@@ -0,0 +1,29 @@
1
+import {program} from "commander";
2
+import {promises as fs} from "node:fs";
3
+
4
+program
5
+ .name("ls")
6
+ .description("List all the files in a directory")
7
+ .option("-a, --all", "Include hidden files")
8
+ .option("-1", "One entry per line")
9
+ .argument("[dir]", "directory to list", ".");
10
11
+program.parse();
12
13
+const options = program.opts();
14
+const dir = program.args[0] || ".";
15
16
+const entries = await fs.readdir(dir, { withFileTypes: true });
17
18
+const visibleNames = [];
19
20
+for(const entry of entries){
21
+ if(!options.all && entry.name.startsWith(".")) continue;
22
+ visibleNames.push(entry.name);
23
+}
24
25
+if(options["1"]){
26
+ console.log(visibleNames.join("\n"));
27
+} else{
28
+ console.log(visibleNames.join(" "));
29
0 commit comments