Skip to content

Commit acb6980

Browse files
committed
feature: add --help support to ls implementation
1 parent d2e7eae commit acb6980

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ for (const arg of argv) {
6666
}
6767
}
6868

69+
if (options.help) {
70+
process.stdout.write("Usage: ls [OPTION]... [FILE]...\n");
71+
process.stdout.write(
72+
"List information about the FILEs (the current directory by default).\n\n",
73+
);
74+
process.stdout.write("Options:\n");
75+
76+
for (const definition of Object.values(validFlags)) {
77+
process.stdout.write(
78+
` ${definition.short}, ${definition.long}\t${definition.description}\n`,
79+
);
80+
}
81+
82+
process.exit(0);
83+
}
84+
6985
if (paths.length === 0) {
7086
paths.push(".");
7187
}

0 commit comments

Comments
 (0)