fix: skip config loading for completion subcommands#109
fix: skip config loading for completion subcommands#109lexfrei merged 1 commit intocozystack:mainfrom
Conversation
Summary of ChangesHello @kitsunoff, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughReplaces a command-name prefix heuristic with a new helper, isCommandOrParent(cmd, ...), that checks the current command and its parents for excluded names (e.g., "init", "completion") before loading configuration in PersistentPreRunE. No other control flow changes were introduced. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
main.go (1)
128-133:⚠️ Potential issue | 🟡 MinorPre-existing:
os.Args[1]will panic if no arguments are provided.Not introduced by this PR, but
os.Args[1]at line 129 will cause an index-out-of-range panic when runningtalmwith no subcommand. Consider guarding with a length check.🛡️ Suggested guard
func initConfig() { + if len(os.Args) < 2 { + return + } cmdName := os.Args[1]
🧹 Nitpick comments (1)
main.go (1)
90-92: Substring match on command path could produce false positives.The fix correctly addresses the original bug. However,
strings.Contains(cmdPath, " init")will also match hypothetical commands like"talm initialize"or"talm reinit". A slightly more robust approach would be to split on spaces and check for exact segment matches.♻️ Optional: tighter matching
- cmdPath := cmd.CommandPath() // e.g. "talm completion bash" - if !strings.Contains(cmdPath, " init") && !strings.Contains(cmdPath, " completion") { + // Check if any segment of the command path is "init" or "completion" + skipConfig := false + for p := cmd; p != nil; p = p.Parent() { + if p.Name() == "init" || p.Name() == "completion" { + skipConfig = true + break + } + } + if !skipConfig {
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where completion subcommands would fail outside of a project directory by attempting to load a configuration file. The approach of using cmd.CommandPath() is correct, but the implementation using strings.Contains is not robust and could lead to bugs with commands that have similar names. I've suggested a more robust, idiomatic cobra approach by traversing the command's parent hierarchy to reliably determine if config loading should be skipped.
Use cmd.Name() with parent traversal instead of cmd.Use to properly detect completion subcommands like "completion bash". Previously, only the leaf command name was checked, causing config loading to fail when Chart.yaml doesn't exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
928948e to
de7ef3c
Compare
The __complete command is cobra's internal hidden command used for shell autocompletion (triggered when user presses Tab). It was not included in the skip list after PR cozystack#109, causing autocompletion to fail outside project directories. Bug reproduction: $ talm __complete ini "" error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory Changes: - Add "__complete" to skipConfigCommands list - Extract command list to a variable for testability and documentation - Add unit tests for isCommandOrParent and skipConfigCommands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The __complete command is cobra's internal hidden command used for shell autocompletion (triggered when user presses Tab). It was not included in the skip list after PR cozystack#109, causing autocompletion to fail outside project directories. Bug reproduction: $ talm __complete ini "" error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory Changes: - Add "__complete" to skipConfigCommands list - Extract command list to a variable for testability and documentation - Add unit tests for isCommandOrParent and skipConfigCommands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The __complete command is cobra's internal hidden command used for shell autocompletion (triggered when user presses Tab). It was not included in the skip list after PR #109, causing autocompletion to fail outside project directories. Bug reproduction: $ talm __complete ini "" error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory Changes: - Add "__complete" to skipConfigCommands list - Extract command list to a variable for testability and documentation - Add unit tests for isCommandOrParent and skipConfigCommands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Summary
completion bash/zsh/fish/powershellcommands failing with "error loading configuration" when run outside a talm project directoryCommandPath()instead ofcmd.Useto properly detect completion subcommandsProblem
Running
talm completion bashoutside a project directory fails:This happens because
cmd.Useforcompletion bashreturns"bash", not"completion", so the skip check doesn't match.Solution
Use
cmd.CommandPath()which returns the full command path (e.g.,"talm completion bash"), then check if it contains the command name.Test plan
talm completion bashoutside a project directory - should output bash completion scripttalm completion zshoutside a project directory - should output zsh completion script🤖 Generated with Claude Code
Summary by CodeRabbit