Skip to content

Commit

Permalink
adding output json to info command (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
enrichman committed Nov 29, 2023
1 parent 7703f30 commit 1b05c40
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
14 changes: 14 additions & 0 deletions acceptance/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
package acceptance_test

import (
"encoding/json"

"github.com/epinio/epinio/pkg/api/core/v1/models"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -27,4 +30,15 @@ var _ = Describe("Info", LMisc, func() {
Expect(out).To(ContainSubstring(`Epinio Client Version: `))
Expect(out).To(ContainSubstring(`OIDC enabled: `))
})

It("succeeds with JSON", func() {
out, err := env.Epinio("", "info", "--output", "json")
Expect(err).ToNot(HaveOccurred(), out)

info := &models.InfoResponse{}
err = json.Unmarshal([]byte(out), info)
Expect(err).ToNot(HaveOccurred(), out)
Expect(info.Platform).ToNot(BeEmpty())
Expect(info.Version).ToNot(BeEmpty())
})
})
10 changes: 8 additions & 2 deletions internal/cli/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
)

// NewInfoCmd returns a new 'epinio info' command
func NewInfoCmd(client *usercmd.EpinioClient) *cobra.Command {
return &cobra.Command{
func NewInfoCmd(client *usercmd.EpinioClient, rootCfg *RootConfig) *cobra.Command {
cmd := &cobra.Command{
Use: "info",
Short: "Shows information about the Epinio environment",
Long: "Shows status and versions for epinio's server-side components.",
Expand All @@ -34,4 +34,10 @@ func NewInfoCmd(client *usercmd.EpinioClient) *cobra.Command {
return nil
},
}

cmd.Flags().VarP(rootCfg.Output, "output", "o", "sets output format [text|json]")
bindFlag(cmd, "output")
bindFlagCompletionFunc(cmd, "output", NewStaticFlagsCompletionFunc(rootCfg.Output.Allowed))

return cmd
}
2 changes: 1 addition & 1 deletion internal/cli/cmd/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("Command 'epinio info'", func() {
output = &bytes.Buffer{}
epinioClient.UI().SetOutput(output)

infoCmd = cmd.NewInfoCmd(epinioClient)
infoCmd = cmd.NewInfoCmd(epinioClient, cmd.NewRootConfig())
})

When("the api returns a complete response", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func NewRootCmd() (*cobra.Command, error) {
rootCmd.AddCommand(
CmdCompletion,
cmd.NewSettingsCmd(client),
cmd.NewInfoCmd(client),
cmd.NewInfoCmd(client, cfg),
cmd.NewClientSyncCmd(client),
cmd.NewGitconfigCmd(client),
cmd.NewNamespaceCmd(client, cfg),
Expand Down
14 changes: 9 additions & 5 deletions internal/cli/usercmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ func (c *EpinioClient) Info() error {
log.Info("start")
defer log.Info("return")

v, err := c.API.Info()
info, err := c.API.Info()
if err != nil {
return err
}

if c.ui.JSONEnabled() {
return c.ui.JSON(info)
}

c.ui.Success().
WithStringValue("Platform", v.Platform).
WithStringValue("Kubernetes Version", v.KubeVersion).
WithStringValue("Epinio Server Version", v.Version).
WithStringValue("Platform", info.Platform).
WithStringValue("Kubernetes Version", info.KubeVersion).
WithStringValue("Epinio Server Version", info.Version).
WithStringValue("Epinio Client Version", version.Version).
WithBoolValue("OIDC enabled", v.OIDCEnabled).
WithBoolValue("OIDC enabled", info.OIDCEnabled).
Msg("Epinio Environment")

return nil
Expand Down

0 comments on commit 1b05c40

Please sign in to comment.