feat: add global --debug flag for debug logging#488
feat: add global --debug flag for debug logging#488heyumeng154-alt wants to merge 11 commits intolarksuite:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a global Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (os.Args)
participant FlagSet as FlagSet (pflag)
participant Root as Root Execute
participant Factory as Factory
participant ErrOut as IOStreams.ErrOut
Client->>FlagSet: provide args (--debug ...)
Root->>FlagSet: RegisterGlobalFlags(&globals)
FlagSet-->>Root: parse -> globals.Debug
Root->>Factory: create Factory
Root->>Factory: set DebugEnabled = globals.Debug
Factory->>ErrOut: Debugf("[DEBUG] ...") (only if DebugEnabled)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/superpowers/specs/2026-04-15-debug-flag-design.md`:
- Around line 63-73: Add a language tag to the fenced code block containing the
debug flow so it satisfies markdownlint MD040; change the opening triple
backticks to include a language (e.g., ```text) for the block that lists the
flow from "用户运行:lark-cli --debug..." through the steps referencing
GlobalOptions.Debug, cmd/root.go, f.DebugEnabled and f.Debugf("message"),
leaving the content unchanged otherwise.
In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md`:
- Line 88: Replace the typo "断assert" with the correct Chinese term "断言" in the
negative-case checklist; locate the string "断assert" (exact text) in the
document and update it to "断言" so terminology is consistent across the spec.
In `@internal/core/config.go`:
- Around line 92-97: FindApp currently treats the literal "default" as an alias
and calls CurrentAppConfig(""), which can recurse when CurrentApp == "default"
and breaks callers that expect literal lookup; revert FindApp to only perform
literal name/appId matching and add a new method ResolveProfileSelector(name
string) on MultiAppConfig that returns CurrentAppConfig("") when name ==
"default" otherwise calls FindApp(name); update CLI/selector callers (e.g.,
cmd/profile/add.go and cmd/profile/use.go) to call ResolveProfileSelector for
alias semantics while leaving other code using FindApp unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3a36bc52-0c15-48b5-a530-d46be70724fe
📒 Files selected for processing (9)
cmd/global_flags.gocmd/global_flags_test.gocmd/root.godocs/superpowers/plans/2026-04-15-debug-flag.mddocs/superpowers/specs/2026-04-15-debug-flag-design.mddocs/superpowers/specs/2026-04-15-debug-flag-test-plan.mdinternal/cmdutil/factory.gointernal/cmdutil/factory_debug_test.gointernal/core/config.go
| ``` | ||
| 1. 用户运行:lark-cli --debug +calendar agenda | ||
| ↓ | ||
| 2. Cobra 解析 --debug 标志到 GlobalOptions.Debug = true | ||
| ↓ | ||
| 3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug | ||
| ↓ | ||
| 4. 命令执行时可调用 f.Debugf("message") | ||
| ↓ | ||
| 5. 如果 DebugEnabled 为 true,消息输出到 stderr;否则不输出 | ||
| ``` |
There was a problem hiding this comment.
Add a language tag to the fenced block at Line 63.
This block currently violates markdownlint MD040 (fenced code block should specify a language).
Suggested edit
-```
+```text
1. 用户运行:lark-cli --debug +calendar agenda
↓
2. Cobra 解析 --debug 标志到 GlobalOptions.Debug = true
↓
3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug
↓
4. 命令执行时可调用 f.Debugf("message")
↓
5. 如果 DebugEnabled 为 true,消息输出到 stderr;否则不输出</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
```suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.22.0)
[warning] 63-63: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/superpowers/specs/2026-04-15-debug-flag-design.md` around lines 63 - 73,
Add a language tag to the fenced code block containing the debug flow so it
satisfies markdownlint MD040; change the opening triple backticks to include a
language (e.g., ```text) for the block that lists the flow from "用户运行:lark-cli
--debug..." through the steps referencing GlobalOptions.Debug, cmd/root.go,
f.DebugEnabled and f.Debugf("message"), leaving the content unchanged otherwise.
| ### 错误场景2:--debug 与无效的命令组合 | ||
|
|
||
| - 命令:`lark-cli --debug invalid-command` | ||
| - 断assert: |
There was a problem hiding this comment.
Fix wording typo at Line 88 (断assert).
Use 断言 to keep terminology consistent and avoid confusion in the negative-case checklist.
Suggested edit
-- 断assert:
+- 断言:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - 断assert: | |
| - 断言: |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md` at line 88,
Replace the typo "断assert" with the correct Chinese term "断言" in the
negative-case checklist; locate the string "断assert" (exact text) in the
document and update it to "断言" so terminology is consistent across the spec.
| // Special case: "default" refers to the currently active app config. | ||
| func (m *MultiAppConfig) FindApp(name string) *AppConfig { | ||
| // Special case: "default" refers to the currently active app | ||
| if name == "default" { | ||
| return m.CurrentAppConfig("") | ||
| } |
There was a problem hiding this comment.
FindApp("default") introduces recursion risk and breaks literal profile lookup semantics.
At Line 95-Line 97, aliasing "default" inside FindApp can recurse forever when CurrentApp == "default" (CurrentAppConfig("") calls FindApp(m.CurrentApp)), and it also changes existing callers that expect literal name/appId matching (e.g., uniqueness checks in cmd/profile/add.go and direct lookup in cmd/profile/use.go).
Proposed fix
// FindApp looks up an app by name, then by appId. Returns nil if not found.
// Name match takes priority: if profile A has Name "X" and profile B has AppId "X",
// FindApp("X") returns profile A.
-// Special case: "default" refers to the currently active app config.
func (m *MultiAppConfig) FindApp(name string) *AppConfig {
- // Special case: "default" refers to the currently active app
- if name == "default" {
- return m.CurrentAppConfig("")
- }
// First pass: match by Name
for i := range m.Apps {
if m.Apps[i].Name != "" && m.Apps[i].Name == name {
return &m.Apps[i]
}
}
// Second pass: match by AppId
for i := range m.Apps {
if m.Apps[i].AppId == name {
return &m.Apps[i]
}
}
return nil
}// Add a separate selector resolver for CLI alias semantics.
func (m *MultiAppConfig) ResolveProfileSelector(name string) *AppConfig {
if name == "default" {
return m.CurrentAppConfig("")
}
return m.FindApp(name)
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/core/config.go` around lines 92 - 97, FindApp currently treats the
literal "default" as an alias and calls CurrentAppConfig(""), which can recurse
when CurrentApp == "default" and breaks callers that expect literal lookup;
revert FindApp to only perform literal name/appId matching and add a new method
ResolveProfileSelector(name string) on MultiAppConfig that returns
CurrentAppConfig("") when name == "default" otherwise calls FindApp(name);
update CLI/selector callers (e.g., cmd/profile/add.go and cmd/profile/use.go) to
call ResolveProfileSelector for alias semantics while leaving other code using
FindApp unchanged.
Change-Id: I3c9f0847cddf8fa9bfe5822f763ec6302e2f062a
Change-Id: I73d6aef8feb385b4a14da24fc44fd6e920b700cd
Add a Debug bool field to the GlobalOptions struct and register a --debug boolean flag in RegisterGlobalFlags to enable debug logging support. Change-Id: I83556abb42b289996aad3d4b333c46c4c81f4bf5
Added DebugEnabled bool field to Factory struct to track debug mode state. Implemented Debugf method to write debug output to stderr with [DEBUG] prefix when debug mode is enabled, following the same pattern as other Factory methods. Change-Id: Ic8200fbfd8b6a42be5280c36920dec158834c8d8 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Change-Id: I4c5f10bb2b61bf76a6b1e40c372862bd51bc597a
This modification parses the --debug flag early in Execute() and passes the Debug value from GlobalOptions to Factory.DebugEnabled, enabling the Debugf() method to output debug messages when the flag is enabled. The parsing uses a temporary pflag.FlagSet to extract the debug value without interfering with the normal Cobra command tree processing. Change-Id: I6f2d16870b8ec0048dae32874c34b53b9a08c8bb
Change-Id: I098d4abbb95fc6091130d537ced86fde80a79d46
Change-Id: I737e12dd01abc6d445a800af27cfbc3731d2c3d4
Add special case handling in FindApp() to resolve --profile default to the currently active app configuration. This allows tests and users to reference the default profile by name without knowing the actual profile name. Fixes failing E2E tests that expect --profile default to work. Change-Id: I4c197873ac99f5bbc251b4bb60424364810537d9
…ommand-arg order Change-Id: Ib2804573074c48af480734912107b46b60e05398
e947c5d to
bb7b31f
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (2)
docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md (1)
88-88:⚠️ Potential issue | 🟡 MinorFix wording typo (
断assert→断言).Line 88 still has mixed wording and should be normalized for consistency.
✏️ Suggested edit
-- 断assert: +- 断言:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md` at line 88, Replace the mixed-language typo "断assert" with the correct Chinese term "断言" in the document; locate the exact string "断assert" in the spec text and update it to "断言" so the wording is consistent throughout the file.docs/superpowers/specs/2026-04-15-debug-flag-design.md (1)
63-73:⚠️ Potential issue | 🟡 MinorAdd a language tag to this fenced block (MD040).
Please specify a language (e.g.,
text) on the opening fence.🧩 Suggested edit
-``` +```text 1. 用户运行:lark-cli --debug +calendar agenda ↓ 2. Cobra 解析 --debug 标志到 GlobalOptions.Debug = true ↓ 3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug ↓ 4. 命令执行时可调用 f.Debugf("message") ↓ 5. 如果 DebugEnabled 为 true,消息输出到 stderr;否则不输出</details> <details> <summary>🤖 Prompt for AI Agents</summary>Verify each finding against the current code and only fix it if needed.
In
@docs/superpowers/specs/2026-04-15-debug-flag-design.mdaround lines 63 - 73,
The fenced code block showing the debug-flag flow lacks a language tag (MD040);
update the opening fence for that block (the triple-backtick that precedes the
numbered steps) to include a language label such as text (e.g., change ``` tofence unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/superpowers/specs/2026-04-15-debug-flag-design.md`:
- Line 68: The code currently sets Factory.DebugEnabled = opts.Debug but the
implementation flow and bootstrap wiring use the global variable named
globals.Debug; update the assignment in cmd/root.go where you create the Factory
(the Factory instance and its DebugEnabled field) to use globals.Debug instead
of opts.Debug so the wiring matches the rest of the codebase.
In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md`:
- Around line 77-84: The test case claiming `lark-cli +calendar --debug agenda`
should not enable global debug conflicts with the bootstrap global-flag parsing;
update the spec so the negative case is removed or rewritten to assert that
`--debug` is recognized as a global flag regardless of position (since the
bootstrap parses global flags from argv before command execution). Edit the
entry containing the example `lark-cli +calendar --debug agenda` and mention the
bootstrap/global-flag parsing behavior (referencing "bootstrap" and the
`--debug` flag) so the test expectations match current implementation.
---
Duplicate comments:
In `@docs/superpowers/specs/2026-04-15-debug-flag-design.md`:
- Around line 63-73: The fenced code block showing the debug-flag flow lacks a
language tag (MD040); update the opening fence for that block (the
triple-backtick that precedes the numbered steps) to include a language label
such as text (e.g., change ``` to ```text) so the markdown linter passes; leave
the block contents and closing fence unchanged.
In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md`:
- Line 88: Replace the mixed-language typo "断assert" with the correct Chinese
term "断言" in the document; locate the exact string "断assert" in the spec text
and update it to "断言" so the wording is consistent throughout the file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 50f5aff5-a1d6-416d-b4f2-e8edecf6bf6e
📒 Files selected for processing (9)
cmd/global_flags.gocmd/global_flags_test.gocmd/root.godocs/superpowers/plans/2026-04-15-debug-flag.mddocs/superpowers/specs/2026-04-15-debug-flag-design.mddocs/superpowers/specs/2026-04-15-debug-flag-test-plan.mdinternal/cmdutil/factory.gointernal/cmdutil/factory_debug_test.gointernal/core/config.go
✅ Files skipped from review due to trivial changes (4)
- cmd/root.go
- cmd/global_flags_test.go
- internal/cmdutil/factory_debug_test.go
- docs/superpowers/plans/2026-04-15-debug-flag.md
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/core/config.go
- cmd/global_flags.go
| ↓ | ||
| 2. Cobra 解析 --debug 标志到 GlobalOptions.Debug = true | ||
| ↓ | ||
| 3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug |
There was a problem hiding this comment.
Use the actual variable name used in implementation flow.
For consistency with the described bootstrap wiring, opts.Debug should be globals.Debug.
🔧 Suggested edit
-3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug
+3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = globals.Debug📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = opts.Debug | |
| 3. cmd/root.go 创建 Factory,设置 f.DebugEnabled = globals.Debug |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/superpowers/specs/2026-04-15-debug-flag-design.md` at line 68, The code
currently sets Factory.DebugEnabled = opts.Debug but the implementation flow and
bootstrap wiring use the global variable named globals.Debug; update the
assignment in cmd/root.go where you create the Factory (the Factory instance and
its DebugEnabled field) to use globals.Debug instead of opts.Debug so the wiring
matches the rest of the codebase.
| ### 错误场景1:--debug 放在命令后面(不是全局标志) | ||
|
|
||
| - 命令:`lark-cli +calendar --debug agenda` | ||
| - 断言: | ||
| - `--debug` 被解释为 `agenda` 命令的参数 | ||
| - 不启用全局调试模式 | ||
| - 可能出现 "unknown flag" 错误或被忽略 | ||
|
|
There was a problem hiding this comment.
This negative case contradicts current global-flag bootstrap behavior.
The plan says lark-cli +calendar --debug agenda should not enable global debug, but current bootstrap parses global flags from argv before command execution. This test expectation is likely incorrect and can create false failures.
📝 Suggested doc update
-### 错误场景1:--debug 放在命令后面(不是全局标志)
+### 场景:--debug 放在命令后面(全局标志兼容性)
- 命令:`lark-cli +calendar --debug agenda`
- 断言:
- - `--debug` 被解释为 `agenda` 命令的参数
- - 不启用全局调试模式
- - 可能出现 "unknown flag" 错误或被忽略
+ - 全局调试模式被启用
+ - 不应出现与 `--debug` 相关的 unknown flag 错误🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/superpowers/specs/2026-04-15-debug-flag-test-plan.md` around lines 77 -
84, The test case claiming `lark-cli +calendar --debug agenda` should not enable
global debug conflicts with the bootstrap global-flag parsing; update the spec
so the negative case is removed or rewritten to assert that `--debug` is
recognized as a global flag regardless of position (since the bootstrap parses
global flags from argv before command execution). Edit the entry containing the
example `lark-cli +calendar --debug agenda` and mention the
bootstrap/global-flag parsing behavior (referencing "bootstrap" and the
`--debug` flag) so the test expectations match current implementation.
Change-Id: I66e14b7e01c650dabd604fb9067ff458363f089f
|
✅ Fixed in commit f708079: Prevented infinite recursion in FindApp by checking if |
|
🔍 Review of remaining CodeRabbit comments:
All critical code issues have been resolved. The feature is complete and tested. |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f7080791c7612ee0312b937356ab4cdcc1924179🧩 Skill updatenpx skills add heyumeng154-alt/cli#feat/add-debug-flag -y -g |
Summary
Add a global
--debugflag that enables verbose debug logging output to stderr across all lark-cli commands.Features
lark-cli --debug <command> [options][DEBUG]prefixChanges
Code Changes
Debug boolfield to GlobalOptions and register--debugflagDebugEnabled boolfield andDebugf()method to FactoryTest Coverage
Documentation
Files Changed
Testing
Acceptance Criteria
Examples
```bash
Enable debug logging for a command
lark-cli --debug api GET /open-apis/contact/v3/users
Combine with other global flags
lark-cli --debug --profile myprofile +calendar agenda
Debug output goes to stderr, normal output to stdout
lark-cli --debug drive files list 2> debug.log
```
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
Documentation