feat(common): add FlagHints + did-you-mean unknown-flag error enhancemen#906
feat(common): add FlagHints + did-you-mean unknown-flag error enhancemen#906xzcong0820 wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a flag-name suggestion system for unknown-flag errors (rune-aware Levenshtein + dynamic threshold), integrates it into Shortcut error handling via FlagHints and a custom SetFlagErrorFunc (SilenceUsage), and configures FlagHints for multiple mail shortcuts. ChangesFlag suggestion system with mail shortcut hints
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ 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 |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@0dcbc8f58825283a89d76febd00a99b41ba66c97🧩 Skill updatenpx skills add xzcong0820/larksuite-cli#feat/8f59c0d -y -g |
05e6c92 to
11e5684
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
shortcuts/common/runner.go (1)
725-741:⚠️ Potential issue | 🟠 Major | ⚡ Quick winScope
SilenceUsageto flag-parse errors onlyLine 728 sets
SilenceUsage: trueat the command level, which suppresses usage output globally for all errors—including positional-arg rejection errors and RunE errors. This exceeds the stated intent ("prevent cobra from printing usage text on flag-parse errors"). MoveSilenceUsage = trueinto the flag error handler to limit suppression to flag-parse errors only.💡 Proposed fix
cmd := &cobra.Command{ Use: shortcut.Command, Short: shortcut.Description, Hidden: shortcut.Hidden, - SilenceUsage: true, // prevent cobra from printing usage text on flag-parse errors Args: rejectPositionalArgs(), RunE: func(cmd *cobra.Command, _ []string) error { return runShortcut(cmd, f, &shortcut, botOnly) }, } @@ sc := shortcut // capture loop variable (required for go < 1.22; safe for go >= 1.22) cmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error { + c.SilenceUsage = true // only silence usage for flag-parse errors return wrapFlagError(&sc, c, err) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/common/runner.go` around lines 725 - 741, The command currently sets SilenceUsage: true on the cobra.Command (in the command literal used by runShortcut), which suppresses usage for all errors; instead leave SilenceUsage false in the command and set c.SilenceUsage = true only inside the SetFlagErrorFunc handler so only flag-parse errors are silenced. Concretely: remove or unset SilenceUsage from the command creation, and in the anonymous function passed to cmd.SetFlagErrorFunc (which currently calls wrapFlagError(&sc, c, err)), set c.SilenceUsage = true before delegating to wrapFlagError so RunE/positional-arg rejections still trigger usage output; keep references to sc (captured shortcut), wrapFlagError, registerShortcutFlagsWithContext, and runShortcut unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@shortcuts/common/runner.go`:
- Around line 725-741: The command currently sets SilenceUsage: true on the
cobra.Command (in the command literal used by runShortcut), which suppresses
usage for all errors; instead leave SilenceUsage false in the command and set
c.SilenceUsage = true only inside the SetFlagErrorFunc handler so only
flag-parse errors are silenced. Concretely: remove or unset SilenceUsage from
the command creation, and in the anonymous function passed to
cmd.SetFlagErrorFunc (which currently calls wrapFlagError(&sc, c, err)), set
c.SilenceUsage = true before delegating to wrapFlagError so RunE/positional-arg
rejections still trigger usage output; keep references to sc (captured
shortcut), wrapFlagError, registerShortcutFlagsWithContext, and runShortcut
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6e1968a3-7606-4271-9ab5-081079c601cf
📒 Files selected for processing (9)
shortcuts/common/flag_suggest.goshortcuts/common/flag_suggest_test.goshortcuts/common/runner.goshortcuts/common/types.goshortcuts/mail/mail_draft_edit.goshortcuts/mail/mail_message.goshortcuts/mail/mail_send.goshortcuts/mail/mail_thread.goshortcuts/mail/mail_triage.go
🚧 Files skipped from review as they are similar to previous changes (4)
- shortcuts/mail/mail_message.go
- shortcuts/mail/mail_send.go
- shortcuts/mail/mail_thread.go
- shortcuts/common/flag_suggest.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #906 +/- ##
==========================================
+ Coverage 65.95% 67.39% +1.44%
==========================================
Files 523 572 +49
Lines 49590 53683 +4093
==========================================
+ Hits 32707 36182 +3475
- Misses 14090 14491 +401
- Partials 2793 3010 +217 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5308ea8 to
23f795d
Compare
Adds a per-shortcut FlagHints map (common/types.go) that lets mail shortcuts declare known flag aliases (e.g. "recipient" → "to"). At mount time, runner.go serialises FlagHints into cmd.Annotations so the data is accessible at error-handling time without creating a circular import between common and mail. mail/flag_suggest.go's flagSuggestErrorFunc gains a Priority-0 path that reads the hint map from cmd.Annotations and inserts the exact-match target as candidates[0] with reason="hint" and distance=0, before the existing prefix + Levenshtein fallback. The hint target is deduplicated from the suggest() results so it never appears twice. FlagHints is configured on five mail shortcuts: - mail_draft_edit, mail_message, mail_send, mail_thread, mail_triage Output format (candidates[] array, error.type="unknown_flag") is unchanged from PR larksuite#806.
Generated by the harness-coding skill.
Sprints
Source specs
This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.
Summary by CodeRabbit
New Features
Bug Fixes
Tests