Skip to content

Commit dd574ac

Browse files
committed
Implement my first own program, cat file2
1 parent 4350f48 commit dd574ac

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

implement-shell-tools/cat/cat.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { program } from "commander";
2+
import { promises as fs } from "node:fs";
3+
4+
program
5+
.name("implement my own version of `cat`.")
6+
.description("I do not know what I'm doing")
7+
.argument("<path>", "The file path to process");
8+
program.parse();
9+
10+
const argv = program.args;
11+
if (argv.length != 1) {
12+
console.error(`Expected exactly 1 argument (a path) to be passed but got ${argv.length}`);
13+
process.exit(1);
14+
}
15+
const path = argv[0];
16+
17+
const content = await fs.readFile(path, "utf-8");
18+
console.log(content);

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

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "cat",
3+
"version": "1.0.0",
4+
"description": "You should already be familiar with the `cat` command line tool.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"commander": "^14.0.3"
14+
}
15+
}

0 commit comments

Comments
 (0)