1 parent
b967ff7f05
commit
72aa110f72
50 files changed
+489
-540
No files matched your search
@@ -2,6 +2,7 @@
|
||||
package sessionscmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
@@ -119,12 +120,12 @@ func (c *Command) Run(args []string) int {
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
c.PrintCliError(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" {
|
||||
c.UI.Error("ID is required but not passed in via -id")
|
||||
c.PrintCliError(errors.New("ID is required but not passed in via -id"))
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ func (c *Command) Run(args []string) int {
|
||||
switch c.Func {
|
||||
case "list":
|
||||
if c.FlagScopeId == "" {
|
||||
c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")
|
||||
c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID"))
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -142,7 +143,7 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
client, err := c.Client()
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error()))
|
||||
c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error()))
|
||||
return 2
|
||||
}
|
||||
sessionsClient := sessions.NewClient(client)
|
||||
@@ -186,16 +187,16 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr)))
|
||||
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
output, err := printCustomActionOutput(c)
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
c.PrintCliError(err)
|
||||
return 1
|
||||
}
|
||||
if output {
|
||||
@@ -213,12 +214,11 @@ func (c *Command) Run(args []string) int {
|
||||
c.UI.Output("null")
|
||||
|
||||
default:
|
||||
b, err := base.JsonFormatter{}.Format(listedItems)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error())
|
||||
return 1
|
||||
items := make([]interface{}, len(listedItems))
|
||||
for i, v := range listedItems {
|
||||
items[i] = v
|
||||
}
|
||||
c.UI.Output(string(b))
|
||||
return c.PrintJsonItems(listResult, items)
|
||||
}
|
||||
|
||||
case "table":
|
||||
@@ -234,12 +234,7 @@ func (c *Command) Run(args []string) int {
|
||||
c.UI.Output(printItemTable(item))
|
||||
|
||||
case "json":
|
||||
b, err := base.JsonFormatter{}.Format(item)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error())
|
||||
return 1
|
||||
}
|
||||
c.UI.Output(string(b))
|
||||
return c.PrintJsonItem(result, item)
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user