Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored and wtrocki committed Apr 11, 2022
1 parent 1213140 commit 2c686f8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
6 changes: 6 additions & 0 deletions docs/commands/rhoas_context_list.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions pkg/cmd/context/contextcmdutil/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ func (v *Validator) ValidateName(val interface{}) error {
return v.Localizer.MustLocalizeError("context.common.validation.name.error.invalidChars", localize.NewEntry("Name", name))
}

// ValidateName validates if the name provided is a unique context name
func (v *Validator) ValidateNameIsAvailable(val interface{}) error {

name, ok := val.(string)
if !ok {
return errors.NewCastError(val, "string")
}
// ValidateNameIsAvailable validates if the name provided is a unique context name
func (v *Validator) ValidateNameIsAvailable(name string) error {

context, _ := v.ProfileHandler.GetContext(name)
if context != nil {
Expand Down
40 changes: 25 additions & 15 deletions pkg/cmd/context/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/redhat-developer/app-services-cli/pkg/cmd/context/contextcmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/icon"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
Expand All @@ -20,6 +22,8 @@ type options struct {
localizer localize.Localizer
Context context.Context
ServiceContext servicecontext.IContext

outputFormat string
}

// NewListCommand creates a new command to list available contexts
Expand All @@ -44,6 +48,10 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
},
}

flags := contextcmdutil.NewFlagSet(cmd, f)

flags.AddOutput(&opts.outputFormat)

return cmd
}

Expand All @@ -57,23 +65,25 @@ func runList(opts *options) error {
profiles := svcContext.Contexts

if profiles == nil {
profiles = make(map[string]servicecontext.ServiceConfig)
opts.Logger.Info(opts.localizer.MustLocalize("context.list.log.info.noContexts"))
return nil
}

currentCtx := svcContext.CurrentContext

var profileList string

for name := range profiles {
if currentCtx != "" && name == currentCtx {
profileList += fmt.Sprintln(name, icon.SuccessPrefix())
} else {
profileList += fmt.Sprintln(name)
switch opts.outputFormat {
case dump.EmptyFormat:
currentCtx := svcContext.CurrentContext
var profileList string

for name := range profiles {
if currentCtx != "" && name == currentCtx {
profileList += fmt.Sprintln(name, icon.SuccessPrefix())
} else {
profileList += fmt.Sprintln(name)
}
}
opts.Logger.Info(profileList)
return nil
default:
return dump.Formatted(opts.IO.Out, opts.outputFormat, profiles)
}

opts.Logger.Info(profileList)
opts.Logger.Info(opts.localizer.MustLocalize("context.list.log.info.describeHint"))

return nil
}
2 changes: 1 addition & 1 deletion pkg/cmd/context/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func runInteractivePrompt(opts *options, context *servicecontext.Context) (strin
}

if len(profileNames) == 0 {
opts.Logger.Info(opts.localizer.MustLocalize("context.list.log.noContexts"))
opts.Logger.Info(opts.localizer.MustLocalize("context.list.log.info.noContexts"))
return "", nil
}

Expand Down
11 changes: 2 additions & 9 deletions pkg/core/localize/locales/en/cmd/context.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,13 @@ one='''
$ rhoas context list
'''

[context.list.log.noContexts]
[context.list.log.info.noContexts]
one='''
No service contexts exist.
Run the following command to create a service context:
rhoas context create
'''

[context.list.log.info.describeHint]
one = '''
Run the following to view the services associated with a context:
$ rhoas context status --name my-context
$ rhoas context create
'''

[context.create.cmd]
Expand Down

0 comments on commit 2c686f8

Please sign in to comment.