Skip to content

Commit 13e4900

Browse files
rkpattnaik780wtrocki
authored andcommitted
refactor(context): change context to service context
1 parent 1dca939 commit 13e4900

File tree

20 files changed

+237
-193
lines changed

20 files changed

+237
-193
lines changed

cmd/rhoas/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/redhat-developer/app-services-cli/pkg/cmd/root"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
11+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1112

1213
"github.com/redhat-developer/app-services-cli/internal/telemetry"
1314
"github.com/redhat-developer/app-services-cli/pkg/core/config"
@@ -20,7 +21,6 @@ import (
2021
"github.com/spf13/cobra"
2122

2223
"github.com/redhat-developer/app-services-cli/internal/build"
23-
"github.com/redhat-developer/app-services-cli/pkg/core/profile"
2424
)
2525

2626
func main() {
@@ -95,7 +95,7 @@ func initConfig(f *factory.Factory) error {
9595
}
9696

9797
func initProfiles(f *factory.Factory) error {
98-
if !profile.HasCustomLocation() {
98+
if !servicecontext.HasCustomLocation() {
9999
rhoasCtxDir, err := config.DefaultDir()
100100
if err != nil {
101101
return err
@@ -110,7 +110,7 @@ func initProfiles(f *factory.Factory) error {
110110
}
111111
}
112112

113-
ctxFile, err := f.Profile.Load()
113+
ctxFile, err := f.ServiceContext.Load()
114114

115115
if ctxFile != nil {
116116
return err
@@ -120,8 +120,8 @@ func initProfiles(f *factory.Factory) error {
120120
return err
121121
}
122122

123-
ctxFile = &profile.Context{}
124-
if err := f.Profile.Save(ctxFile); err != nil {
123+
ctxFile = &servicecontext.Context{}
124+
if err := f.ServiceContext.Save(ctxFile); err != nil {
125125
return err
126126
}
127127
return nil

docs/commands/rhoas_context.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/commands/rhoas_context_create.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/commands/rhoas_context_list.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cmd/context/create/create.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
99
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
11-
"github.com/redhat-developer/app-services-cli/pkg/core/profile"
11+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1212
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1313
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1414
"github.com/spf13/cobra"
1515
)
1616

1717
type options struct {
18-
IO *iostreams.IOStreams
19-
Logger logging.Logger
20-
Connection factory.ConnectionFunc
21-
localizer localize.Localizer
22-
Context context.Context
23-
Profiles profile.IContext
18+
IO *iostreams.IOStreams
19+
Logger logging.Logger
20+
Connection factory.ConnectionFunc
21+
localizer localize.Localizer
22+
Context context.Context
23+
ServiceContext servicecontext.IContext
2424

2525
name string
2626
kafkaID string
@@ -31,11 +31,11 @@ type options struct {
3131
func NewCreateCommand(f *factory.Factory) *cobra.Command {
3232

3333
opts := &options{
34-
Connection: f.Connection,
35-
IO: f.IOStreams,
36-
Logger: f.Logger,
37-
localizer: f.Localizer,
38-
Profiles: f.Profile,
34+
Connection: f.Connection,
35+
IO: f.IOStreams,
36+
Logger: f.Logger,
37+
localizer: f.Localizer,
38+
ServiceContext: f.ServiceContext,
3939
}
4040

4141
cmd := &cobra.Command{
@@ -61,7 +61,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {
6161

6262
func runCreate(opts *options) error {
6363

64-
context, err := opts.Profiles.Load()
64+
context, err := opts.ServiceContext.Load()
6565
if err != nil {
6666
return err
6767
}
@@ -74,15 +74,15 @@ func runCreate(opts *options) error {
7474
profiles := context.Contexts
7575

7676
if profiles == nil {
77-
profiles = map[string]profile.ServiceConfig{}
77+
profiles = map[string]servicecontext.ServiceConfig{}
7878
}
7979

8080
currentCtx, _ := profileHandler.GetContext(opts.name)
8181
if currentCtx != nil {
8282
return opts.localizer.MustLocalizeError("context.create.log.alreadyExists", localize.NewEntry("Name", opts.name))
8383
}
8484

85-
services := profile.ServiceConfig{
85+
services := servicecontext.ServiceConfig{
8686
KafkaID: opts.kafkaID,
8787
ServiceRegistryID: opts.registryID,
8888
}
@@ -91,7 +91,7 @@ func runCreate(opts *options) error {
9191

9292
context.Contexts = profiles
9393

94-
err = opts.Profiles.Save(context)
94+
err = opts.ServiceContext.Save(context)
9595
if err != nil {
9696
return err
9797
}

pkg/cmd/context/list/list.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@ package list
22

33
import (
44
"context"
5+
"fmt"
56

7+
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/icon"
68
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
79
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
810
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
9-
"github.com/redhat-developer/app-services-cli/pkg/core/profile"
11+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1012
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1113
"github.com/spf13/cobra"
1214
)
1315

1416
type options struct {
15-
IO *iostreams.IOStreams
16-
Logger logging.Logger
17-
Connection factory.ConnectionFunc
18-
localizer localize.Localizer
19-
Context context.Context
20-
Profiles profile.IContext
17+
IO *iostreams.IOStreams
18+
Logger logging.Logger
19+
Connection factory.ConnectionFunc
20+
localizer localize.Localizer
21+
Context context.Context
22+
ServiceContext servicecontext.IContext
2123
}
2224

2325
// NewListCommand creates a new command to list available contexts
2426
func NewListCommand(f *factory.Factory) *cobra.Command {
2527

2628
opts := &options{
27-
Connection: f.Connection,
28-
IO: f.IOStreams,
29-
Logger: f.Logger,
30-
localizer: f.Localizer,
31-
Profiles: f.Profile,
29+
Connection: f.Connection,
30+
IO: f.IOStreams,
31+
Logger: f.Logger,
32+
localizer: f.Localizer,
33+
ServiceContext: f.ServiceContext,
3234
}
3335

3436
cmd := &cobra.Command{
@@ -47,28 +49,30 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
4749

4850
func runList(opts *options) error {
4951

50-
context, err := opts.Profiles.Load()
52+
context, err := opts.ServiceContext.Load()
5153
if err != nil {
5254
return err
5355
}
5456

5557
profiles := context.Contexts
5658

5759
if profiles == nil {
58-
profiles = map[string]profile.ServiceConfig{}
60+
profiles = map[string]servicecontext.ServiceConfig{}
5961
}
6062

61-
profileNames := make([]string, 0, len(profiles))
63+
currentCtx := context.CurrentContext
6264

63-
if len(profileNames) == 0 {
64-
opts.Logger.Info(opts.localizer.MustLocalize("context.list.log.noContexts"))
65-
}
65+
var profileList string
6666

6767
for name := range profiles {
68-
profileNames = append(profileNames, name)
68+
if currentCtx != "" && name == currentCtx {
69+
profileList += fmt.Sprintln(name, icon.SuccessPrefix())
70+
} else {
71+
profileList += fmt.Sprintln(name)
72+
}
6973
}
7074

71-
opts.Logger.Info(profileNames)
75+
opts.Logger.Info(profileList)
7276

7377
return nil
7478
}

pkg/cmd/context/status/status.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import (
88
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
99
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
11+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1112
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1213
"github.com/spf13/cobra"
1314

14-
"github.com/redhat-developer/app-services-cli/pkg/core/profile"
1515
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1616
)
1717

1818
type options struct {
19-
IO *iostreams.IOStreams
20-
Logger logging.Logger
21-
Connection factory.ConnectionFunc
22-
localizer localize.Localizer
23-
Context context.Context
24-
Profiles profile.IContext
19+
IO *iostreams.IOStreams
20+
Logger logging.Logger
21+
Connection factory.ConnectionFunc
22+
localizer localize.Localizer
23+
Context context.Context
24+
ServiceContext servicecontext.IContext
2525

2626
name string
2727
outputFormat string
@@ -31,11 +31,11 @@ type options struct {
3131
func NewStatusCommand(f *factory.Factory) *cobra.Command {
3232

3333
opts := &options{
34-
Connection: f.Connection,
35-
IO: f.IOStreams,
36-
Logger: f.Logger,
37-
localizer: f.Localizer,
38-
Profiles: f.Profile,
34+
Connection: f.Connection,
35+
IO: f.IOStreams,
36+
Logger: f.Logger,
37+
localizer: f.Localizer,
38+
ServiceContext: f.ServiceContext,
3939
}
4040

4141
cmd := &cobra.Command{
@@ -59,10 +59,10 @@ func NewStatusCommand(f *factory.Factory) *cobra.Command {
5959

6060
func runStatus(opts *options) error {
6161

62-
var currentCtx *profile.ServiceConfig
62+
var currentCtx *servicecontext.ServiceConfig
6363
var err error
6464

65-
context, err := opts.Profiles.Load()
65+
context, err := opts.ServiceContext.Load()
6666
if err != nil {
6767
return err
6868
}

0 commit comments

Comments
 (0)