Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat(service-registry): setting command #1677

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/commands/rhoas_service-registry.md

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

34 changes: 34 additions & 0 deletions docs/commands/rhoas_service-registry_setting.md

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

42 changes: 42 additions & 0 deletions docs/commands/rhoas_service-registry_setting_get.md

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

40 changes: 40 additions & 0 deletions docs/commands/rhoas_service-registry_setting_list.md

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

43 changes: 43 additions & 0 deletions docs/commands/rhoas_service-registry_setting_set.md

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

2 changes: 2 additions & 0 deletions pkg/cmd/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/describe"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/list"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/rule"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/setting"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/use"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/spf13/cobra"
Expand All @@ -36,6 +37,7 @@ func NewServiceRegistryCommand(f *factory.Factory) *cobra.Command {
artifact.NewArtifactsCommand(f),
role.NewRoleCommand(f),
rule.NewRuleCommand(f),
setting.NewSettingCommand(f),
)

return cmd
Expand Down
109 changes: 109 additions & 0 deletions pkg/cmd/registry/setting/get/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package get

import (
"github.com/AlecAivazis/survey/v2"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/rule/rulecmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/spf13/cobra"

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

type options struct {
registryID string
settingName string
output string

f *factory.Factory
}

// NewGetCommand creates a new command to get a service registry setting
func NewGetCommand(f *factory.Factory) *cobra.Command {

opts := &options{
f: f,
}

cmd := &cobra.Command{
Use: "get",
Short: f.Localizer.MustLocalize("setting.get.cmd.description.short"),
Long: f.Localizer.MustLocalize("setting.get.cmd.description.long"),
Example: f.Localizer.MustLocalize("setting.get.cmd.example"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) (err error) {

if opts.settingName == "" {
if !opts.f.IOStreams.CanPrompt() {
return flagutil.RequiredWhenNonInteractiveError("name")
}
err = runInteractivePrompt(opts)
if err != nil {
return err
}
}

if opts.registryID != "" {
return runGet(opts)
}

registryInstance, err := contextutil.GetCurrentRegistryInstance(f)
if err != nil {
return err
}

opts.registryID = registryInstance.GetId()
SafarMirek marked this conversation as resolved.
Show resolved Hide resolved

return runGet(opts)
},
}

flags := rulecmdutil.NewFlagSet(cmd, f)

flags.AddRegistryInstance(&opts.registryID)

flags.StringVarP(&opts.settingName, "name", "n", "", f.Localizer.MustLocalize("setting.get.cmd.flag.settingName.description"))

flags.AddOutput(&opts.output)

return cmd
}

func runGet(opts *options) error {
conn, err := opts.f.Connection()
if err != nil {
return err
}

api := conn.API()

a, _, err := api.ServiceRegistryInstance(opts.registryID)
if err != nil {
return err
}

request := a.AdminApi.GetConfigProperty(opts.f.Context, opts.settingName)

configProperty, _, err := request.Execute()
if err != nil {
return registrycmdutil.TransformInstanceError(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Really really nice that you have found and used that method.

}

return dump.Formatted(opts.f.IOStreams.Out, opts.output, configProperty)
}

func runInteractivePrompt(opts *options) (err error) {

settingNamePrompt := &survey.Input{
Message: opts.f.Localizer.MustLocalize("setting.get.input.settingName.message"),
}

err = survey.AskOne(settingNamePrompt, &opts.settingName)
if err != nil {
return err
}

return nil
}
Loading