Skip to content

Commit f733fb4

Browse files
rkpattnaik780wtrocki
authored andcommitted
refactor(context): rename profileutil and add flag completions
1 parent b39b37d commit f733fb4

File tree

55 files changed

+129
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+129
-111
lines changed

pkg/cmd/context/contextcmdutil/flagset.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func NewFlagSet(cmd *cobra.Command, f *factory.Factory) *FlagSet {
2323

2424
// AddContextName adds a flag for setting the name of the context
2525
func (fs *FlagSet) AddContextName(name *string) *flagutil.FlagOptions {
26+
27+
svcContext, _ := fs.factory.ServiceContext.Load()
28+
29+
svcContextsMap := svcContext.Contexts
2630
flagName := "name"
2731

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

39+
contextNames := make([]string, 0, len(svcContextsMap))
40+
for k := range svcContextsMap {
41+
contextNames = append(contextNames, k)
42+
}
43+
44+
_ = fs.cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
45+
return contextNames, cobra.ShellCompDirectiveNoSpace
46+
})
47+
3548
return flagutil.WithFlagOptions(fs.cmd, flagName)
3649

3750
}

pkg/cmd/context/contextcmdutil/validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55

66
"github.com/redhat-developer/app-services-cli/pkg/core/errors"
77
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
8-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
8+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
99
)
1010

1111
// Validator is a type for validating service context inputs
1212
type Validator struct {
1313
Localizer localize.Localizer
14-
ProfileHandler *profileutil.ContextHandler
14+
ProfileHandler *contextutil.ContextHandler
1515
}
1616

1717
const (

pkg/cmd/context/create/create.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1111
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
12+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1213
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
13-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1414
"github.com/spf13/cobra"
1515
)
1616

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

5151
flags := contextcmdutil.NewFlagSet(cmd, f)
5252

53-
_ = flags.AddContextName(&opts.name).Required()
53+
flags.StringVar(
54+
&opts.name,
55+
"name",
56+
"",
57+
opts.localizer.MustLocalize("context.common.flag.name"),
58+
)
5459

5560
return cmd
5661

@@ -63,7 +68,7 @@ func runCreate(opts *options) error {
6368
return err
6469
}
6570

66-
profileHandler := &profileutil.ContextHandler{
71+
profileHandler := &contextutil.ContextHandler{
6772
Context: svcContext,
6873
Localizer: opts.localizer,
6974
}

pkg/cmd/context/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1111
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
12+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1213
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
13-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1414
"github.com/spf13/cobra"
1515
)
1616

@@ -61,7 +61,7 @@ func runDelete(opts *options) error {
6161
return err
6262
}
6363

64-
profileHandler := &profileutil.ContextHandler{
64+
profileHandler := &contextutil.ContextHandler{
6565
Context: svcContext,
6666
Localizer: opts.localizer,
6767
}

pkg/cmd/context/use/use.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1212
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1313
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
14+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1415
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
15-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1616
"github.com/spf13/cobra"
1717
)
1818

@@ -75,7 +75,7 @@ func runUse(opts *options) error {
7575
}
7676
}
7777

78-
profileHandler := &profileutil.ContextHandler{
78+
profileHandler := &contextutil.ContextHandler{
7979
Context: svcContext,
8080
Localizer: opts.localizer,
8181
}

pkg/cmd/kafka/acl/admin/admin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1515
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1616
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
17+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1718
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
18-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1919
"github.com/spf13/cobra"
2020

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

69-
profileHandler := &profileutil.ContextHandler{
69+
profileHandler := &contextutil.ContextHandler{
7070
Context: svcContext,
7171
Localizer: opts.localizer,
7272
}

pkg/cmd/kafka/acl/create/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/spinner"
1111
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1212
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
13+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1314
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
14-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1515
kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
1616
"github.com/spf13/cobra"
1717
)
@@ -237,7 +237,7 @@ func validateAndSetOpts(opts *aclcmdutil.CrudOptions) error {
237237
return err
238238
}
239239

240-
profileHandler := &profileutil.ContextHandler{
240+
profileHandler := &contextutil.ContextHandler{
241241
Context: svcContext,
242242
Localizer: opts.Localizer,
243243
}

pkg/cmd/kafka/acl/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/spinner"
1212
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1313
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
14+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1415
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
15-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1616
kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1internal/client"
1717
"github.com/spf13/cobra"
1818
)
@@ -283,7 +283,7 @@ func validateAndSetOpts(opts *aclcmdutil.CrudOptions) error {
283283
return err
284284
}
285285

286-
profileHandler := &profileutil.ContextHandler{
286+
profileHandler := &contextutil.ContextHandler{
287287
Context: svcContext,
288288
Localizer: opts.Localizer,
289289
}

pkg/cmd/kafka/acl/grant/grant.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1515
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1616
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
17+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
1718
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
18-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1919
"github.com/spf13/cobra"
2020

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

76-
profileHandler := &profileutil.ContextHandler{
76+
profileHandler := &contextutil.ContextHandler{
7777
Context: svcContext,
7878
Localizer: opts.localizer,
7979
}

pkg/cmd/kafka/acl/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/aclcmdutil"
77
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/flagutil"
8+
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
89
kafkacmdutil "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
9-
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1010

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

83-
profileHandler := &profileutil.ContextHandler{
83+
profileHandler := &contextutil.ContextHandler{
8484
Context: svcContext,
8585
Localizer: opts.localizer,
8686
}

0 commit comments

Comments
 (0)