Use stdout in registry writer only with commands that don't use structured output

Signed-off-by: divolgin <dmitriy@replicated.com>
pull/11593/head
divolgin 3 years ago
parent 76157c6d06
commit 5140b246ac

@ -53,6 +53,8 @@ func newGetValuesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compListReleases(toComplete, args, cfg)
},
RunE: func(cmd *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
vals, err := client.Run(args[0])
if err != nil {
return err

@ -67,6 +67,8 @@ func newHistoryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compListReleases(toComplete, args, cfg)
},
RunE: func(cmd *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
history, err := getHistory(client, args[0])
if err != nil {
return err

@ -136,6 +136,8 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compInstall(args, toComplete, client)
},
RunE: func(_ *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
rel, err := runInstall(args, client, valueOpts, out)
if err != nil {
return errors.Wrap(err, "INSTALLATION FAILED")

@ -70,6 +70,8 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
Args: require.NoArgs,
ValidArgsFunction: noCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
if client.AllNamespaces {
if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug); err != nil {
return err

@ -30,6 +30,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli/output"
"helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/repo"
)
@ -155,7 +156,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
registryClient, err := registry.NewClient(
registry.ClientOptDebug(settings.Debug),
registry.ClientOptEnableCache(true),
registry.ClientOptWriter(os.Stderr),
registry.ClientOptWriter(out),
registry.ClientOptCredentialsFile(settings.RegistryConfig),
)
if err != nil {
@ -261,3 +262,10 @@ func checkForExpiredRepos(repofile string) {
}
}
func overrideRegistryWriter(cfg *action.Configuration, outfmt output.Format) {
// Ensure registry output doesn't break structured output
if outfmt != output.Table {
registry.ClientOptWriter(os.Stderr)(cfg.RegistryClient)
}
}

@ -65,6 +65,7 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compListReleases(toComplete, args, cfg)
},
RunE: func(cmd *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
// When the output format is a table the resources should be fetched
// and displayed as a table. When YAML or JSON the resources will be

@ -34,6 +34,7 @@ import (
"helm.sh/helm/v3/cmd/helm/require"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli/output"
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/releaseutil"
)
@ -65,6 +66,8 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compInstall(args, toComplete, client)
},
RunE: func(_ *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, output.YAML)
if kubeVersion != "" {
parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion)
if err != nil {

@ -88,6 +88,8 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return nil, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
overrideRegistryWriter(cfg, outfmt)
client.Namespace = settings.Namespace()
// Fixes #7002 - Support reading values from STDIN for `upgrade` command

Loading…
Cancel
Save