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 e328bd5 commit 57a3c2aCopy full SHA for 57a3c2a
implement-shell-tools/ls/ls.mjs
@@ -0,0 +1,24 @@
1
+import { program } from "commander"
2
+import process from "node:process"
3
+import { promises as fs } from "node:fs"
4
+import { readdir } from 'node:fs/promises'
5
+
6
+program
7
+ .name("ls")
8
+ .description("Lists the files in a directory")
9
+ .option("-1, --one", "One per line")
10
+ .option("-a", "Include files starting with dot")
11
+ .argument("filepath")
12
+program.parse(process.argv)
13
14
+const argv = program.args
15
+const opts = program.opts()
16
17
+if (argv.length != 1){
18
+ console.error("Expected 1 argument")
19
+ process.exit(1)
20
+}
21
22
+const content = await fs.readdir(argv[0])
23
24
+console.log(content.join(opts.one ? "\n": " "))
0 commit comments