Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-tools-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Preserve equals signs in inline CLI option values after the first separator.
10 changes: 8 additions & 2 deletions packages/effect/src/unstable/cli/internal/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ const lexTokens = (args: ReadonlyArray<string>): ReadonlyArray<Token> => {
if (!arg.startsWith("-")) {
tokens.push({ _tag: "Value", value: arg })
} else if (arg.startsWith("--")) {
const [name, value] = arg.slice(2).split("=", 2)
tokens.push({ _tag: "LongOption", name, raw: arg, value })
const equalIndex = arg.indexOf("=")
if (equalIndex !== -1) {
const name = arg.slice(2, equalIndex)
const value = arg.slice(equalIndex + 1)
tokens.push({ _tag: "LongOption", name, raw: arg, value })
} else {
tokens.push({ _tag: "LongOption", name: arg.slice(2), raw: arg })
}
} else if (arg.length > 1) {
const flags = arg.slice(1)
const equalIndex = flags.indexOf("=")
Expand Down
15 changes: 15 additions & 0 deletions packages/effect/test/unstable/cli/Lexer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { assert, describe, it } from "@effect/vitest"
import * as Lexer from "effect/unstable/cli/internal/lexer"

describe("Lexer", () => {
it("preserves every equals sign in a long option's inline value", () => {
const result = Lexer.lex(["--query=left=right"])

assert.deepStrictEqual(result.tokens, [{
_tag: "LongOption",
name: "query",
raw: "--query=left=right",
value: "left=right"
}])
})
})
Loading