diff --git a/.changeset/kind-cups-bow.md b/.changeset/kind-cups-bow.md new file mode 100644 index 0000000000..4b025777b3 --- /dev/null +++ b/.changeset/kind-cups-bow.md @@ -0,0 +1,5 @@ +--- +"@effect/cli": patch +--- + +Allow using the equals (`=`) character inside aliased key value params. diff --git a/packages/cli/src/internal/options.ts b/packages/cli/src/internal/options.ts index ff3bcb096c..d01b11be1e 100644 --- a/packages/cli/src/internal/options.ts +++ b/packages/cli/src/internal/options.ts @@ -1149,6 +1149,9 @@ const toParseableInstruction = (self: Instruction): Array } } +/** @internal */ +const keyValueSplitter = /=(.*)/ + const parseInternal = ( self: Instruction, args: HashMap.HashMap>, @@ -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]) } diff --git a/packages/cli/test/Options.test.ts b/packages/cli/test/Options.test.ts index 96cfb955fa..f493f2e91a 100644 --- a/packages/cli/test/Options.test.ts +++ b/packages/cli/test/Options.test.ts @@ -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(