Skip to content

Commit 852b400

Browse files
committed
works with regular inputs
1 parent d6556ad commit 852b400

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

implement-shell-tools/cat/cat.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { program } from "commander";
2+
import { promises as fs } from "node:fs";
3+
4+
program.argument("<files...>").parse();
5+
6+
for (const file of program.args) {
7+
const stat = await fs.stat(file);
8+
9+
if (stat.isDirectory()) {
10+
console.error(`cat: ${file}: Is a directory`);
11+
continue;
12+
}
13+
14+
const content = await fs.readFile(file, "utf-8");
15+
process.stdout.write(content);
16+
}

implement-shell-tools/cat/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+
"dependencies": {
3+
"commander": "^14.0.3"
4+
},
5+
"type": "module"
6+
}

0 commit comments

Comments
 (0)