Skip to content

Commit 79a15eb

Browse files
kitsunoffclaude
andauthored
fix: skip config loading for completion subcommands (#109)
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) Signed-off-by: ZverGuy <maximbel2003@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent d69aa8d commit 79a15eb

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ func init() {
8787
}
8888

8989
// Load config after root detection (skip for init and completion commands)
90-
cmdName := cmd.Use
91-
if !strings.HasPrefix(cmdName, "init") && !strings.HasPrefix(cmdName, "completion") {
90+
if !isCommandOrParent(cmd, "init", "completion") {
9291
configFile := filepath.Join(commands.Config.RootDir, "Chart.yaml")
9392
if err := loadConfig(configFile); err != nil {
9493
return fmt.Errorf("error loading configuration: %w", err)
@@ -143,6 +142,18 @@ func initConfig() {
143142
}
144143
}
145144

145+
// isCommandOrParent checks if the command or any of its parents matches one of the given names.
146+
func isCommandOrParent(cmd *cobra.Command, names ...string) bool {
147+
for c := cmd; c != nil; c = c.Parent() {
148+
for _, name := range names {
149+
if c.Name() == name {
150+
return true
151+
}
152+
}
153+
}
154+
return false
155+
}
156+
146157
func loadConfig(filename string) error {
147158
data, err := os.ReadFile(filename)
148159
if err != nil {

0 commit comments

Comments
 (0)