-
Notifications
You must be signed in to change notification settings - Fork 66
WIP: feat(service-registry): setting command #1677
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package get | ||
|
|
||
| import ( | ||
| "context" | ||
| "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/core/ioutil/iostreams" | ||
| "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/factory" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/redhat-developer/app-services-cli/pkg/shared/contextutil" | ||
| ) | ||
|
|
||
| type options struct { | ||
| IO *iostreams.IOStreams | ||
| Connection factory.ConnectionFunc | ||
| Logger logging.Logger | ||
| localizer localize.Localizer | ||
| Context context.Context | ||
| ServiceContext servicecontext.IContext | ||
|
|
||
| registryID string | ||
| settingName string | ||
| output string | ||
| } | ||
|
|
||
| // NewGetCommand creates a new command to get a service registry setting | ||
| func NewGetCommand(f *factory.Factory) *cobra.Command { | ||
|
|
||
| opts := &options{ | ||
| IO: f.IOStreams, | ||
| Connection: f.Connection, | ||
| Logger: f.Logger, | ||
| localizer: f.Localizer, | ||
| Context: f.Context, | ||
| ServiceContext: f.ServiceContext, | ||
| } | ||
|
|
||
| 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.IO.CanPrompt() { | ||
| return flagutil.RequiredWhenNonInteractiveError("setting-name") | ||
SafarMirek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| err = runInteractivePrompt(opts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| 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, "setting-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.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.Context, opts.settingName) | ||
|
|
||
| configProperty, _, err := request.Execute() | ||
| if err != nil { | ||
| return registrycmdutil.TransformInstanceError(err) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.IO.Out, opts.output, configProperty) | ||
| } | ||
|
|
||
| func runInteractivePrompt(opts *options) (err error) { | ||
|
|
||
| settingNamePrompt := &survey.Input{ | ||
| Message: opts.localizer.MustLocalize("setting.get.input.settingName.message"), | ||
| } | ||
|
|
||
| err = survey.AskOne(settingNamePrompt, &opts.settingName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.