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 e2983ea commit 0f7b2b0Copy full SHA for 0f7b2b0
1 file changed
implement-shell-tools/ls/ls.mjs
@@ -0,0 +1,24 @@
1
+import { promises as fs } from "node:fs";
2
+import { program } from "commander";
3
+
4
+program
5
+ .name("ls ")
6
+ .description("ls implementation")
7
+ .argument("[path]", "The path to process") //zero or one path
8
+ .option("-1, --one-per-line", "one file per line")
9
+ .option("-a", "show hidden files");
10
+program.parse();
11
12
+const path = program.args[0] || ".";
13
+const options = program.opts();
14
+try {
15
+ const files = await fs.readdir(path);
16
17
+ for (const file of files) {
18
+ if (options.a || !file.startsWith(".")) {
19
+ console.log(file);
20
+ }
21
22
+} catch (error) {
23
+ console.error(error.message);
24
+}
0 commit comments