Skip to content

Commit

Permalink
Fix helm output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Jul 17, 2023
1 parent aed3a23 commit ed82f89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
8 changes: 4 additions & 4 deletions internal/executor/helm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ func (e *Executor) Execute(ctx context.Context, in executor.ExecuteInput) (execu
return e.handleHelmCommand(ctx, helmCmd.Get.Values, cfg, wasHelpRequested, in.Command, kubeConfigPath)
default:
return executor.ExecuteOutput{
Data: helmCmd.Get.Help(),
Message: api.NewCodeBlockMessage(helmCmd.Get.Help(), true),
}, nil
}
default:
return executor.ExecuteOutput{
Data: "Helm command not supported",
Message: api.NewCodeBlockMessage("Helm command not supported", true),
}, nil
}
}
Expand All @@ -171,7 +171,7 @@ func (*Executor) Help(context.Context) (api.Message, error) {
func (e *Executor) handleHelmCommand(ctx context.Context, cmd command, cfg Config, wasHelpRequested bool, rawCmd, kubeConfig string) (executor.ExecuteOutput, error) {
if wasHelpRequested {
return executor.ExecuteOutput{
Data: cmd.Help(),
Message: api.NewCodeBlockMessage(cmd.Help(), true),
}, nil
}

Expand All @@ -193,7 +193,7 @@ func (e *Executor) handleHelmCommand(ctx context.Context, cmd command, cfg Confi
}

return executor.ExecuteOutput{
Message: api.NewPlaintextMessage(out.Stdout, true),
Message: api.NewCodeBlockMessage(out.Stdout, true),
}, nil
}

Expand Down
8 changes: 6 additions & 2 deletions internal/executor/helm/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helm

import (
"context"
"encoding/json"
"fmt"
"testing"

Expand Down Expand Up @@ -79,7 +80,7 @@ func TestExecutorHelmInstall(t *testing.T) {
// then
require.NoError(t, err)

assert.Equal(t, api.NewPlaintextMessage(execOutput.Stdout, true), out.Message)
assert.Equal(t, api.NewCodeBlockMessage(execOutput.Stdout, true), out.Message)

assert.Equal(t, tc.expCommand, gotCmd)

Expand Down Expand Up @@ -174,7 +175,10 @@ func TestExecutorHelmInstallHelp(t *testing.T) {

// then
require.NoError(t, err)
golden.Assert(t, out.Data, goldenFilepath)
gotOut, err := json.MarshalIndent(out.Message, "", " ")
require.NoError(t, err)

golden.AssertBytes(t, gotOut, goldenFilepath)
})
}
}
Expand Down
48 changes: 12 additions & 36 deletions internal/executor/helm/testdata/TestExecutorHelmInstallHelp.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
Installs a chart archive.

There are two different ways you to install a Helm chart:
1. By absolute URL: helm install mynginx https://example.com/charts/nginx-1.2.3.tgz
2. By chart reference and repo url: helm install --repo https://example.com/charts/ mynginx nginx

Usage:
helm install [NAME] [CHART] [flags]

Flags:
--create-namespace
--generate-name,-g
--dependency-update
--description
--devel
--disable-openapi-validation
--dry-run
--insecure-skip-tls-verify
--name-template
--no-hooks
--pass-credentials
--password
--post-renderer
--post-renderer-args
--render-subchart-notes
--replace
--repo
--set
--set-json
--set-string
--skip-crds
--timeout
--username
--verify
--version
-o,--output
{
"Type": "baseBodyWithFilter",
"BaseBody": {
"CodeBlock": "Installs a chart archive.\n\nThere are two different ways you to install a Helm chart:\n1. By absolute URL: helm install mynginx https://example.com/charts/nginx-1.2.3.tgz\n2. By chart reference and repo url: helm install --repo https://example.com/charts/ mynginx nginx\n\nUsage:\n helm install [NAME] [CHART] [flags]\n\nFlags:\n --create-namespace\n --generate-name,-g\n --dependency-update\n --description\n --devel\n --disable-openapi-validation\n --dry-run\n --insecure-skip-tls-verify\n --name-template\n --no-hooks\n --pass-credentials\n --password\n --post-renderer\n --post-renderer-args\n --render-subchart-notes\n --replace\n --repo\n --set\n --set-json\n --set-string\n --skip-crds\n --timeout\n --username\n --verify\n --version\n -o,--output\n",
"Plaintext": ""
},
"Timestamp": "0001-01-01T00:00:00Z",
"Sections": null,
"PlaintextInputs": null,
"OnlyVisibleForYou": false,
"ReplaceOriginal": false
}

0 comments on commit ed82f89

Please sign in to comment.