Skip to content

Commit

Permalink
Fix completion command to not require Chart.yaml
Browse files Browse the repository at this point in the history
fixes #20

Signed-off-by: Andrei Kvapil <[email protected]>
  • Loading branch information
kvaps committed Aug 20, 2024
1 parent e9a10a3 commit 441b7bf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,27 @@ func init() {
}

func initConfig() {
cmd, _, _ := rootCmd.Find(os.Args[1:])
if cmd == nil {
cmdName := os.Args[1]
cmd, _, err := rootCmd.Find([]string{cmdName})
if err != nil || cmd == nil {
return
}
if cmd.HasParent() && cmd.Parent() != rootCmd {
cmd = cmd.Parent()
}
if strings.HasPrefix(cmd.Use, "init") {
if strings.HasPrefix(Version, "v") {
commands.Config.InitOptions.Version = strings.TrimPrefix(Version, `v`)
} else {
commands.Config.InitOptions.Version = "0.1.0"
}
} else {
configFile := filepath.Join(commands.Config.RootDir, "Chart.yaml")
if err := loadConfig(configFile); err != nil {
fmt.Fprintf(os.Stderr, "Error loading configuration: %v\n", err)
os.Exit(1)
if !strings.HasPrefix(cmd.Use, "completion") {
configFile := filepath.Join(commands.Config.RootDir, "Chart.yaml")
if err := loadConfig(configFile); err != nil {
fmt.Fprintf(os.Stderr, "Error loading configuration: %v\n", err)
os.Exit(1)
}
}
}
}
Expand Down

0 comments on commit 441b7bf

Please sign in to comment.