diff --git a/src/core/util/parser.ts b/src/core/util/parser.ts index 7d66610..067b625 100644 --- a/src/core/util/parser.ts +++ b/src/core/util/parser.ts @@ -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); } diff --git a/test/core/util/parser.test.ts b/test/core/util/parser.test.ts index 13cafbf..74afc0a 100644 --- a/test/core/util/parser.test.ts +++ b/test/core/util/parser.test.ts @@ -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"] }); });