Parser fully finished and functional, posix compliant and tested - all green

This commit is contained in:
2026-07-24 15:11:44 +02:00
parent 355a8a4707
commit b63bae54aa
2 changed files with 20 additions and 0 deletions
+4
View File
@@ -123,6 +123,10 @@ export function parseCommand(input: string): ParsedCommand {
flags.push(token.slice(2));
continue;
} else if (token.startsWith("-")) {
if (token.includes("=")) {
flags.push(token.slice(1));
continue;
}
for (const char of token.slice(1)) {
flags.push(char);
}
+16
View File
@@ -43,6 +43,22 @@ describe("parseCommand", () => {
});
});
test("returns a parsed grep command with a valued color in short form and r flags", () => {
expect(parseCommand("grep -color=auto -r")).toEqual({
command: "grep",
flags: ["color=auto", "r"],
args: [],
});
});
test("returns a parsed grep command with a valued w in short form and r flags", () => {
expect(parseCommand("grep -w=auto -r")).toEqual({
command: "grep",
flags: ["w=auto", "r"],
args: [],
});
});
test("returns a parsed echo command with a --version arg", () => {
expect(parseCommand("echo -- --version")).toEqual({ command: "echo", flags: [], args: ["--version"] });
});