refactor(api module): enforce typed definitions (#2238)
This commit is contained in:
1 parent
d6c1402223
commit
c2bfcc0664
79 files changed
+906
-551
No files matched your search
@@ -62,8 +62,7 @@ func (c *Command) printListTable(items []*managedgroups.ManagedGroup) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*managedgroups.ManagedGroup)
|
||||
func printItemTable(item *managedgroups.ManagedGroup, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -195,24 +195,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *managedgroups.ManagedGroup
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*managedgroups.ManagedGroup
|
||||
|
||||
var readResult *managedgroups.ManagedGroupReadResult
|
||||
|
||||
var deleteResult *managedgroups.ManagedGroupDeleteResult
|
||||
|
||||
var listResult *managedgroups.ManagedGroupListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = managedgroupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = managedgroupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = managedgroupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = managedgroupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = managedgroupsClient.List(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, managedgroupsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, managedgroupsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -239,7 +251,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -252,13 +264,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*managedgroups.ManagedGroup)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -267,10 +278,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -285,8 +296,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]managedgroups.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *managedgroups.ManagedGroup, inItems []*managedgroups.ManagedGroup, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (*api.Response, *managedgroups.ManagedGroup, []*managedgroups.ManagedGroup, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -193,19 +193,28 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *managedgroups.ManagedGroup
|
||||
|
||||
var createResult *managedgroups.ManagedGroupCreateResult
|
||||
|
||||
var updateResult *managedgroups.ManagedGroupUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = managedgroupsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
createResult, err = managedgroupsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = managedgroupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = managedgroupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraOidcActions(c, result, err, managedgroupsClient, version, opts)
|
||||
resp, item, err = executeExtraOidcActions(c, resp, item, err, managedgroupsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -233,10 +242,10 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -249,8 +258,8 @@ var (
|
||||
extraOidcSynopsisFunc = func(*OidcCommand) string { return "" }
|
||||
extraOidcFlagsFunc = func(*OidcCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraOidcFlagsHandlingFunc = func(*OidcCommand, *base.FlagSets, *[]managedgroups.Option) bool { return true }
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResult api.GenericResult, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResp *api.Response, inItem *managedgroups.ManagedGroup, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (*api.Response, *managedgroups.ManagedGroup, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomOidcActionOutput = func(*OidcCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
Reference in new issue
Block a user