Parser fully finished and functional, posix compliant and tested - all green
This commit is contained in:
@@ -123,6 +123,10 @@ export function parseCommand(input: string): ParsedCommand {
|
|||||||
flags.push(token.slice(2));
|
flags.push(token.slice(2));
|
||||||
continue;
|
continue;
|
||||||
} else if (token.startsWith("-")) {
|
} else if (token.startsWith("-")) {
|
||||||
|
if (token.includes("=")) {
|
||||||
|
flags.push(token.slice(1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (const char of token.slice(1)) {
|
for (const char of token.slice(1)) {
|
||||||
flags.push(char);
|
flags.push(char);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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", () => {
|
test("returns a parsed echo command with a --version arg", () => {
|
||||||
expect(parseCommand("echo -- --version")).toEqual({ command: "echo", flags: [], args: ["--version"] });
|
expect(parseCommand("echo -- --version")).toEqual({ command: "echo", flags: [], args: ["--version"] });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user