Skip to content

Commit 56cac6c

Browse files
Implement basic cat with no flags
1 parent 407b010 commit 56cac6c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import process from "node:process"
2+
import {promises as fs} from "node:fs"
3+
4+
const argv = process.argv.slice(2)
5+
6+
if (argv.length != 1) {
7+
console.error(
8+
`Expected exactly 1 argument (a path) to be passed but got ${argv.length}.`
9+
);
10+
process.exit(1);
11+
}
12+
13+
const path = argv[0]
14+
15+
16+
const content = await fs.readFile(path, "utf-8")
17+
console.log(content)

0 commit comments

Comments
 (0)