move logic from cmd/helm to pkg/cmd

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
pull/30618/head
Austin Abro 7 months ago
parent 20c75f0c10
commit 022d4db6af
No known key found for this signature in database
GPG Key ID: 92EB5159E403F9D6

@ -23,7 +23,6 @@ import (
// Import to initialize client auth plugins. // Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
"helm.sh/helm/v4/pkg/action"
helmcmd "helm.sh/helm/v4/pkg/cmd" helmcmd "helm.sh/helm/v4/pkg/cmd"
"helm.sh/helm/v4/pkg/kube" "helm.sh/helm/v4/pkg/kube"
) )
@ -39,8 +38,7 @@ func main() {
// manager as picked up by the automated name detection. // manager as picked up by the automated name detection.
kube.ManagedFieldsManager = "helm" kube.ManagedFieldsManager = "helm"
actionConfig := new(action.Configuration) cmd, err := helmcmd.NewRootCmd(os.Stdout, os.Args[1:])
cmd, err := helmcmd.NewRootCmd(actionConfig, os.Stdout, os.Args[1:])
if err != nil { if err != nil {
helmcmd.Warning("%+v", err) helmcmd.Warning("%+v", err)
os.Exit(1) os.Exit(1)

@ -95,7 +95,7 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
Log: func(_ string, _ ...interface{}) {}, Log: func(_ string, _ ...interface{}) {},
} }
root, err := NewRootCmd(actionConfig, buf, args) root, err := newRootCmdWithConfig(actionConfig, buf, args)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }

@ -106,7 +106,26 @@ func Warning(format string, v ...interface{}) {
fmt.Fprintf(os.Stderr, "WARNING: "+format+"\n", v...) fmt.Fprintf(os.Stderr, "WARNING: "+format+"\n", v...)
} }
func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) (*cobra.Command, error) { func NewRootCmd(out io.Writer, args []string) (*cobra.Command, error) {
actionConfig := new(action.Configuration)
cmd, err := newRootCmdWithConfig(actionConfig, out, args)
if err != nil {
return nil, err
}
cobra.OnInitialize(func() {
helmDriver := os.Getenv("HELM_DRIVER")
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), helmDriver, Debug); err != nil {
log.Fatal(err)
}
if helmDriver == "memory" {
loadReleasesInMemory(actionConfig)
}
actionConfig.SetHookOutputFunc(hookOutputWriter)
})
return cmd, nil
}
func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, args []string) (*cobra.Command, error) {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", Short: "The Helm package manager for Kubernetes.",
@ -124,16 +143,6 @@ func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
}, },
} }
cobra.OnInitialize(func() {
helmDriver := os.Getenv("HELM_DRIVER")
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), helmDriver, Debug); err != nil {
log.Fatal(err)
}
if helmDriver == "memory" {
loadReleasesInMemory(actionConfig)
}
actionConfig.SetHookOutputFunc(hookOutputWriter)
})
flags := cmd.PersistentFlags() flags := cmd.PersistentFlags()
settings.AddFlags(flags) settings.AddFlags(flags)

Loading…
Cancel
Save