Skip to content

Commit

Permalink
feat: allow equals sign in aliased parameter values. (#2755)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpnova authored Jul 17, 2024
1 parent a9d7800 commit 51e9c5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/kind-cups-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/cli": patch
---

Allow using the equals (`=`) character inside aliased key value params.
5 changes: 4 additions & 1 deletion packages/cli/src/internal/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,9 @@ const toParseableInstruction = (self: Instruction): Array<ParseableInstruction>
}
}

/** @internal */
const keyValueSplitter = /=(.*)/

const parseInternal = (
self: Instruction,
args: HashMap.HashMap<string, ReadonlyArray<string>>,
Expand Down Expand Up @@ -1198,7 +1201,7 @@ const parseInternal = (
const extractKeyValue = (
value: string
): Effect.Effect<[string, string], ValidationError.ValidationError> => {
const split = value.trim().split("=")
const split = value.trim().split(keyValueSplitter, 2)
if (Arr.isNonEmptyReadonlyArray(split) && split.length === 2 && split[1] !== "") {
return Effect.succeed(split as unknown as [string, string])
}
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/test/Options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ describe("Options", () => {
expect(result).toEqual([["--verbose"], HashMap.make(["key1", "v1"], ["key2", "v2"])])
}).pipe(runEffect))

it("keyValueMap - validates key/values with equals in alias value", () =>
Effect.gen(function*(_) {
const args = Array.make("-d", "key1=v1", "key2=v2=vv", "--verbose")
const result = yield* _(process(defs, args, CliConfig.defaultConfig))
expect(result).toEqual([["--verbose"], HashMap.make(["key1", "v1"], ["key2", "v2=vv"])])
}).pipe(runEffect))

it("keyValueMap - validates key/values with equals in aliased longer value", () =>
Effect.gen(function*(_) {
const args = Array.make("-d", "key1=v1", "key2=v2=1+1", "--verbose")
const result = yield* _(process(defs, args, CliConfig.defaultConfig))
expect(result).toEqual([["--verbose"], HashMap.make(["key1", "v1"], ["key2", "v2=1+1"])])
}).pipe(runEffect))

it("keyValueMap - validate should keep non-key-value parameters that follow the key-value pairs (each preceded by alias -d)", () =>
Effect.gen(function*(_) {
const args = Array.make(
Expand Down

0 comments on commit 51e9c5c

Please sign in to comment.