Skip to content

fix: skip config loading for completion subcommands#109

Merged
lexfrei merged 1 commit intocozystack:mainfrom
kitsunoff:fix/completion-command-config-loading
Feb 7, 2026
Merged

fix: skip config loading for completion subcommands#109
lexfrei merged 1 commit intocozystack:mainfrom
kitsunoff:fix/completion-command-config-loading

Conversation

@kitsunoff
Copy link
Contributor

@kitsunoff kitsunoff commented Feb 7, 2026

Summary

  • Fix completion bash/zsh/fish/powershell commands failing with "error loading configuration" when run outside a talm project directory
  • Use CommandPath() instead of cmd.Use to properly detect completion subcommands

Problem

Running talm completion bash outside a project directory fails:

$ talm completion bash
error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory

This happens because cmd.Use for completion bash returns "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

  • Run talm completion bash outside a project directory - should output bash completion script
  • Run talm completion zsh outside a project directory - should output zsh completion script

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved configuration loading so it correctly skips initialization and completion commands and their subcommands.
    • Enhanced command-path detection to ensure initialization and completion flows no longer trigger unnecessary config loading, improving startup reliability.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 talm completion subcommands would erroneously attempt to load a configuration file, leading to failures when run outside a project's root directory. By refining the command identification logic to use cmd.CommandPath(), the system now correctly bypasses configuration loading for these specific commands, ensuring their reliable operation regardless of the current working directory.

Highlights

  • Bug Fix: Resolved an issue where completion subcommands (e.g., talm completion bash) failed when executed outside a project directory due to an attempt to load a configuration file (Chart.yaml).
  • Command Detection Improvement: Updated the command detection mechanism from cmd.Use to cmd.CommandPath() to accurately identify init and completion subcommands, including their full path (e.g., talm completion bash).
  • Configuration Loading Logic: Ensured that configuration loading is correctly skipped for init and completion commands, preventing errors when the project's Chart.yaml is not present in the current working directory.

🧠 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
  • main.go
    • Changed the command name retrieval from cmd.Use to cmd.CommandPath() to obtain the full command path (e.g., "talm completion bash").
    • Modified the conditional check for skipping configuration loading to use strings.Contains on the full command path, allowing correct identification of init and completion subcommands.
Activity
  • The pull request was authored by kitsunoff.
  • The changes were generated with Claude Code.
  • The author provided a clear problem description, solution, and test plan in the pull request body.
  • The test plan includes verification for talm completion bash and talm completion zsh outside a project directory, both marked as passed.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

Replaces 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

Cohort / File(s) Summary
Configuration Loading & Command Checks
main.go
Added helper isCommandOrParent(cmd *cobra.Command, names ...string) bool; replaced prior Use-based prefix check with this parent-aware check to decide whether to call loadConfig in PersistentPreRunE.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through commands both near and far,
Sniffed parents and children to find each spar,
No more false matches from a lonely Use,
I guard config loading — no more misuse! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: fixing config loading to skip completion subcommands. It is concise and specific.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
main.go (1)

126-143: Pre-existing: os.Args[1] can panic if no arguments are provided.

Not introduced by this PR, but os.Args[1] on line 127 will cause an index-out-of-range panic if talm is invoked with no arguments. Also, this function still uses strings.HasPrefix(cmd.Use, "init") rather than the new isCommandOrParent helper — consider unifying the approach for consistency in a follow-up.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Pre-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 running talm with 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 {

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@kitsunoff kitsunoff force-pushed the fix/completion-command-config-loading branch from 928948e to de7ef3c Compare February 7, 2026 19:29
@lexfrei lexfrei self-requested a review February 7, 2026 19:43
@lexfrei lexfrei merged commit 79a15eb into cozystack:main Feb 7, 2026
4 checks passed
kitsunoff added a commit to kitsunoff/talm that referenced this pull request Feb 15, 2026
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>
kitsunoff added a commit to kitsunoff/talm that referenced this pull request Feb 15, 2026
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>
lexfrei pushed a commit that referenced this pull request Feb 15, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants