Skip to content

Commit

Permalink
refactor(context): rename profileutil and add flag completions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored and wtrocki committed Apr 11, 2022
1 parent b39b37d commit f733fb4
Show file tree
Hide file tree
Showing 55 changed files with 129 additions and 111 deletions.
13 changes: 13 additions & 0 deletions pkg/cmd/context/contextcmdutil/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func NewFlagSet(cmd *cobra.Command, f *factory.Factory) *FlagSet {

// AddContextName adds a flag for setting the name of the context
func (fs *FlagSet) AddContextName(name *string) *flagutil.FlagOptions {

svcContext, _ := fs.factory.ServiceContext.Load()

svcContextsMap := svcContext.Contexts
flagName := "name"

fs.StringVar(
Expand All @@ -32,6 +36,15 @@ func (fs *FlagSet) AddContextName(name *string) *flagutil.FlagOptions {
fs.factory.Localizer.MustLocalize("context.common.flag.name"),
)

contextNames := make([]string, 0, len(svcContextsMap))
for k := range svcContextsMap {
contextNames = append(contextNames, k)
}

_ = fs.cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return contextNames, cobra.ShellCompDirectiveNoSpace
})

return flagutil.WithFlagOptions(fs.cmd, flagName)

}
4 changes: 2 additions & 2 deletions pkg/cmd/context/contextcmdutil/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (

"github.com/redhat-developer/app-services-cli/pkg/core/errors"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
)

// Validator is a type for validating service context inputs
type Validator struct {
Localizer localize.Localizer
ProfileHandler *profileutil.ContextHandler
ProfileHandler *contextutil.ContextHandler
}

const (
Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/context/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,7 +50,12 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {

flags := contextcmdutil.NewFlagSet(cmd, f)

_ = flags.AddContextName(&opts.name).Required()
flags.StringVar(
&opts.name,
"name",
"",
opts.localizer.MustLocalize("context.common.flag.name"),
)

return cmd

Expand All @@ -63,7 +68,7 @@ func runCreate(opts *options) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/context/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -61,7 +61,7 @@ func runDelete(opts *options) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/context/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -75,7 +75,7 @@ func runUse(opts *options) error {
}
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/acl/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"

kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
Expand Down Expand Up @@ -66,7 +66,7 @@ func NewAdminACLCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/acl/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/spinner"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -237,7 +237,7 @@ func validateAndSetOpts(opts *aclcmdutil.CrudOptions) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.Localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/acl/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/spinner"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -283,7 +283,7 @@ func validateAndSetOpts(opts *aclcmdutil.CrudOptions) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.Localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/acl/grant/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"

kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
Expand Down Expand Up @@ -73,7 +73,7 @@ func NewGrantPermissionsACLCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/acl/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/aclcmdutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
Expand Down Expand Up @@ -80,7 +80,7 @@ func NewListACLCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/consumergroup/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

kafkaflagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

"github.com/AlecAivazis/survey/v2"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
Expand Down Expand Up @@ -58,7 +58,7 @@ func NewDeleteConsumerGroupCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/consumergroup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"sort"

"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/color"
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewDescribeConsumerGroupCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/consumergroup/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
kafkaflagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"

"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"

"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
Expand Down Expand Up @@ -83,7 +83,7 @@ func NewListConsumerGroupCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/consumergroup/resetoffset/reset_offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/consumergroup/groupcmdutil"
kafkaflagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

"github.com/AlecAivazis/survey/v2"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
Expand Down Expand Up @@ -82,7 +82,7 @@ func NewResetOffsetConsumerGroupCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
kafkaFlagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/kafkacmdutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/accountmgmtutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/remote"
"github.com/redhat-developer/app-services-cli/pkg/shared/svcstatus"
"k8s.io/utils/strings/slices"
Expand Down Expand Up @@ -143,7 +143,7 @@ func runCreate(opts *options) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/kafka/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -68,7 +68,7 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func runDelete(opts *options) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"

Expand Down Expand Up @@ -134,7 +134,7 @@ func runList(opts *options) error {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/topic/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -97,7 +97,7 @@ func NewCreateTopicCommand(f *factory.Factory) *cobra.Command {
return err
}

profileHandler := &profileutil.ContextHandler{
profileHandler := &contextutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}
Expand Down
Loading

0 comments on commit f733fb4

Please sign in to comment.