Skip to content

Commit f6d926d

Browse files
committed
ls_implementation
1 parent 68c884e commit f6d926d

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

implement-shell-tools/ls/ls.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {program} from "commander";
2+
import process from "node:process";
3+
import {promises as fs } from "node:fs";
4+
5+
6+
program
7+
.name ("list command clone")
8+
.description("List all files & folders within current folder")
9+
.argument("[directory]","Directory to list",".")
10+
.option("-1","list file line by line")
11+
.action(async (directory,options) =>
12+
{
13+
try
14+
{
15+
let files = await fs.readdir(directory);
16+
console.log(files.join(" "));
17+
}
18+
19+
catch (error)
20+
{
21+
console.error('No such file or directory');
22+
process.exit(1);
23+
}
24+
25+
});
26+
27+
program.parse(process.argv);

implement-shell-tools/ls/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "module",
3+
"dependencies": {
4+
"commander": "^15.0.0"
5+
}
6+
}

0 commit comments

Comments
 (0)