From 05784237234ceb3f5ebaeaec30701cbd5c97f002 Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Wed, 4 May 2022 10:06:15 +0200 Subject: [PATCH] chore: improvements --- rhoc/pkg/cmd/clusters/clusters.go | 2 -- rhoc/pkg/cmd/config/config.go | 7 ++-- rhoc/pkg/cmd/config/show/show.go | 35 +++++++++++-------- .../cmd/config/token/{config.go => token.go} | 17 +++++---- rhoc/pkg/cmd/connectors/connectors.go | 4 +-- rhoc/pkg/cmd/connectors/list/list_dumper.go | 2 +- rhoc/pkg/cmd/deployments/deployments.go | 7 ++-- rhoc/pkg/cmd/deployments/list/list_dumper.go | 4 +-- rhoc/pkg/cmd/namespaces/namespaces.go | 2 -- 9 files changed, 38 insertions(+), 42 deletions(-) rename rhoc/pkg/cmd/config/token/{config.go => token.go} (70%) diff --git a/rhoc/pkg/cmd/clusters/clusters.go b/rhoc/pkg/cmd/clusters/clusters.go index 6608dec..87cc4d2 100644 --- a/rhoc/pkg/cmd/clusters/clusters.go +++ b/rhoc/pkg/cmd/clusters/clusters.go @@ -12,8 +12,6 @@ import ( func NeClustersCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "clusters", - Short: "clusters", - Long: "clusters", Aliases: []string{"cc"}, Args: cobra.MinimumNArgs(1), } diff --git a/rhoc/pkg/cmd/config/config.go b/rhoc/pkg/cmd/config/config.go index a2902c1..fb2b40d 100644 --- a/rhoc/pkg/cmd/config/config.go +++ b/rhoc/pkg/cmd/config/config.go @@ -14,10 +14,9 @@ type itemRow struct { func NewConfigCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ - Use: "config", - Short: "config", - Long: "config", - Args: cobra.NoArgs, + Use: "config", + Aliases: []string{"cfg"}, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return nil }, diff --git a/rhoc/pkg/cmd/config/show/show.go b/rhoc/pkg/cmd/config/show/show.go index f0bfd3d..83205f4 100644 --- a/rhoc/pkg/cmd/config/show/show.go +++ b/rhoc/pkg/cmd/config/show/show.go @@ -1,34 +1,39 @@ package show import ( - "github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump" + "github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/dumper" "github.com/redhat-developer/app-services-cli/pkg/shared/factory" "github.com/spf13/cobra" ) +type keyVal struct { + key string + val string +} + func NewConfigShowCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ - Use: "show", - Short: "show", - Long: "show", - Args: cobra.NoArgs, + Use: "show", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { c, err := f.Config.Load() if err != nil { return err } - rows := []struct { - Key string `json:"key" header:"Key"` - Val string `json:"val" header:"Val"` - }{ - {Key: "APIUrl", Val: c.APIUrl}, - {Key: "AuthURL", Val: c.AuthURL}, - {Key: "MasAuthURL", Val: c.MasAuthURL}, - } + t := dumper.Table[keyVal]{} + t.Field("Key", func(in *keyVal) string { + return in.key + }) + t.Field("Val", func(in *keyVal) string { + return in.val + }) - dump.Table(f.IOStreams.Out, rows) - f.Logger.Info("") + t.Dump(f.IOStreams.Out, []keyVal{ + {key: "API URL", val: c.APIUrl}, + {key: "Auth URL", val: c.AuthURL}, + {key: "Mas Auth URL", val: c.MasAuthURL}, + }) return nil }, diff --git a/rhoc/pkg/cmd/config/token/config.go b/rhoc/pkg/cmd/config/token/token.go similarity index 70% rename from rhoc/pkg/cmd/config/token/config.go rename to rhoc/pkg/cmd/config/token/token.go index c811ba4..3f0d3c6 100644 --- a/rhoc/pkg/cmd/config/token/config.go +++ b/rhoc/pkg/cmd/config/token/token.go @@ -2,19 +2,14 @@ package token import ( "github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/service" - "github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil" "github.com/redhat-developer/app-services-cli/pkg/shared/factory" "github.com/spf13/cobra" ) func NewConfigTokenCommand(f *factory.Factory) *cobra.Command { - var mas bool - cmd := &cobra.Command{ - Use: "token", - Short: "token", - Long: "token", - Args: cobra.NoArgs, + Use: "token", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { a, err := service.API(&service.Config{ F: f, @@ -23,6 +18,11 @@ func NewConfigTokenCommand(f *factory.Factory) *cobra.Command { return err } + mas, err := cmd.Flags().GetBool("mas") + if err != nil { + return err + } + if mas { _, _ = f.IOStreams.Out.Write([]byte(a.GetConfig().MasAccessToken)) } else { @@ -33,8 +33,7 @@ func NewConfigTokenCommand(f *factory.Factory) *cobra.Command { }, } - flags := flagutil.NewFlagSet(cmd, f.Localizer) - flags.BoolVarP(&mas, "mas", "m", false, "mas") + cmd.Flags().BoolP("mas", "m", false, "mas") return cmd } diff --git a/rhoc/pkg/cmd/connectors/connectors.go b/rhoc/pkg/cmd/connectors/connectors.go index 0891873..d6d3889 100644 --- a/rhoc/pkg/cmd/connectors/connectors.go +++ b/rhoc/pkg/cmd/connectors/connectors.go @@ -12,9 +12,7 @@ import ( func NewConnectorsCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "connectors", - Aliases: []string{"mctr"}, - Short: "connectors", - Long: "connectors", + Aliases: []string{"ctr"}, Args: cobra.MinimumNArgs(1), } diff --git a/rhoc/pkg/cmd/connectors/list/list_dumper.go b/rhoc/pkg/cmd/connectors/list/list_dumper.go index c1214fe..8ab73e7 100644 --- a/rhoc/pkg/cmd/connectors/list/list_dumper.go +++ b/rhoc/pkg/cmd/connectors/list/list_dumper.go @@ -38,7 +38,7 @@ func dumpAsTable(f *factory.Factory, items admin.ConnectorAdminViewList, wide bo }) if wide { - t.Field("ResourceVersion", func(in *admin.ConnectorAdminView) string { + t.Field("Version", func(in *admin.ConnectorAdminView) string { return strconv.FormatInt(in.ResourceVersion, 10) }) } diff --git a/rhoc/pkg/cmd/deployments/deployments.go b/rhoc/pkg/cmd/deployments/deployments.go index 386754a..5031db4 100644 --- a/rhoc/pkg/cmd/deployments/deployments.go +++ b/rhoc/pkg/cmd/deployments/deployments.go @@ -10,10 +10,9 @@ import ( func NewDeploymentsCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ - Use: "deployments", - Short: "deployments", - Long: "deployments", - Args: cobra.MinimumNArgs(1), + Use: "deployments", + Aliases: []string{"cd"}, + Args: cobra.MinimumNArgs(1), } cmdutil.Bind( diff --git a/rhoc/pkg/cmd/deployments/list/list_dumper.go b/rhoc/pkg/cmd/deployments/list/list_dumper.go index d504f1e..9de5a4d 100644 --- a/rhoc/pkg/cmd/deployments/list/list_dumper.go +++ b/rhoc/pkg/cmd/deployments/list/list_dumper.go @@ -32,11 +32,11 @@ func dumpAsTable(f *factory.Factory, items admin.ConnectorDeploymentAdminViewLis if wide { - t.Field("ResourceVersion", func(in *admin.ConnectorDeploymentAdminView) string { + t.Field("Version", func(in *admin.ConnectorDeploymentAdminView) string { return strconv.FormatInt(in.Metadata.ResourceVersion, 10) }) - t.Field("ConnectorResourceVersion", func(in *admin.ConnectorDeploymentAdminView) string { + t.Field("ConnectorVersion", func(in *admin.ConnectorDeploymentAdminView) string { return strconv.FormatInt(in.Spec.ConnectorResourceVersion, 10) }) } diff --git a/rhoc/pkg/cmd/namespaces/namespaces.go b/rhoc/pkg/cmd/namespaces/namespaces.go index f9143ef..de271b2 100644 --- a/rhoc/pkg/cmd/namespaces/namespaces.go +++ b/rhoc/pkg/cmd/namespaces/namespaces.go @@ -14,8 +14,6 @@ func NewNamespacesCommand(f *factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "namespaces", Aliases: []string{"ns"}, - Short: "namespaces", - Long: "namespaces", Args: cobra.MinimumNArgs(1), }