Skip to content

Commit f8273c9

Browse files
authored
fix log level cli arg infinite loop (#5677)
1 parent 7d28a90 commit f8273c9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

.changeset/ten-crabs-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/cli": patch
3+
---
4+
5+
fix log level cli arg infinite loop

packages/cli/src/internal/cliApp.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const handleBuiltInOption = <R, E, A>(
162162
const nextArgs = executable.split(/\s+/)
163163
// Filter out the log level option before re-executing the command
164164
for (let i = 0; i < args.length; i++) {
165-
if (args[i] === "--log-level" || args[i - 1] === "--log-level") {
165+
if (isLogLevelArg(args[i]) || isLogLevelArg(args[i - 1])) {
166166
continue
167167
}
168168
nextArgs.push(args[i])
@@ -356,3 +356,7 @@ const renderWizardArgs = (args: ReadonlyArray<string>) => {
356356
))
357357
])
358358
}
359+
360+
const isLogLevelArg = (arg?: string) => {
361+
return arg && (arg === "--log-level" || arg.startsWith("--log-level="))
362+
}

packages/cli/test/CliApp.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,21 @@ describe("CliApp", () => {
9797
yield* cli(["node", "logging.js", "--log-level", "debug"])
9898
expect(logLevel).toEqual(LogLevel.Debug)
9999
}).pipe(runEffect))
100+
101+
it("should set the minimum log level when using equals syntax (--log-level=...)", () =>
102+
Effect.gen(function*() {
103+
let logLevel: LogLevel.LogLevel | undefined = undefined
104+
const logging = Command.make("logging").pipe(Command.withHandler(() =>
105+
Effect.gen(function*() {
106+
logLevel = yield* FiberRef.get(FiberRef.currentMinimumLogLevel)
107+
})
108+
))
109+
const cli = Command.run(logging, {
110+
name: "Test",
111+
version: "1.0.0"
112+
})
113+
yield* cli(["node", "logging.js", "--log-level=debug"])
114+
expect(logLevel).toEqual(LogLevel.Debug)
115+
}).pipe(runEffect))
100116
})
101117
})

0 commit comments

Comments
 (0)