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/fix-cli-log-level-equals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/cli": patch
---

Fix `--log-level=value` equals syntax incorrectly swallowing the next argument. Only skip the next arg when the previous arg is exactly `--log-level` (space-separated form).
2 changes: 1 addition & 1 deletion packages/cli/src/internal/cliApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const handleBuiltInOption = <R, E, A>(
const baseArgs = Arr.take(originalArgs, 2)
const filteredArgs: Array<string> = []
for (let i = 0; i < args.length; i++) {
if (isLogLevelArg(args[i]) || isLogLevelArg(args[i - 1])) {
if (isLogLevelArg(args[i]) || args[i - 1] === "--log-level") {
continue
}
filteredArgs.push(args[i])
Expand Down
33 changes: 33 additions & 0 deletions packages/cli/test/CliApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,38 @@ describe("CliApp", () => {
yield* cli(["C:\\Program Files\\node.exe", "C:\\My Scripts\\test.js", "--log-level", "info", "hello"])
expect(executedValue).toEqual("hello")
}).pipe(runEffect))

it("should not swallow the next argument when using --log-level=value equals syntax", () =>
Effect.gen(function*() {
let executedValue: string | undefined = undefined
const cmd = Command.make("test", { value: Args.text() }, ({ value }) =>
Effect.sync(() => {
executedValue = value
}))
const cli = Command.run(cmd, {
name: "Test",
version: "1.0.0"
})
yield* cli(["node", "test.js", "--log-level=debug", "hello"])
expect(executedValue).toEqual("hello")
}).pipe(runEffect))

it("should set log level and preserve argument with --log-level=value combined", () =>
Effect.gen(function*() {
let logLevel: LogLevel.LogLevel | undefined = undefined
let executedValue: string | undefined = undefined
const cmd = Command.make("test", { value: Args.text() }, ({ value }) =>
Effect.gen(function*() {
logLevel = yield* FiberRef.get(FiberRef.currentMinimumLogLevel)
executedValue = value
}))
const cli = Command.run(cmd, {
name: "Test",
version: "1.0.0"
})
yield* cli(["node", "test.js", "--log-level=info", "hello"])
expect(logLevel).toEqual(LogLevel.Info)
expect(executedValue).toEqual("hello")
}).pipe(runEffect))
})
})
Loading