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

Fastedge API change #33

Merged
merged 9 commits into from
Apr 13, 2024
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
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/G-core/gcore-cli

go 1.21.5


require (
github.com/G-Core/FastEdge-client-sdk-go v0.0.0-20240304075046-db0c8c3d17e7
github.com/G-Core/FastEdge-client-sdk-go v0.2.0
github.com/alecthomas/assert v1.0.0
github.com/docker/go-units v0.5.0
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.16.0
github.com/golang-module/carbon/v2 v2.3.10
Expand All @@ -23,8 +21,8 @@ require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getkin/kin-openapi v0.123.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -37,7 +35,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -47,7 +45,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
28 changes: 13 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/G-Core/FastEdge-client-sdk-go v0.0.0-20240214130448-d87df1e38764 h1:7CATrk7BJpU1t4wr2avczZaX1KrwsjhArBKBaiSQN2M=
github.com/G-Core/FastEdge-client-sdk-go v0.0.0-20240214130448-d87df1e38764/go.mod h1:ggyUVhy8/OCMBY4nbm7n9qDoPioROCk4vHhDJq9w7qE=
github.com/G-Core/FastEdge-client-sdk-go v0.0.0-20240304075046-db0c8c3d17e7 h1:99yyAfaF6OV2ghz75yE72LwdzxP6gUYa3hL7XkObb5s=
github.com/G-Core/FastEdge-client-sdk-go v0.0.0-20240304075046-db0c8c3d17e7/go.mod h1:ggyUVhy8/OCMBY4nbm7n9qDoPioROCk4vHhDJq9w7qE=
github.com/G-Core/FastEdge-client-sdk-go v0.2.0 h1:OHibIpVO/7kEG1eKy+5i0jcb1urPNm9EKUdH84entpk=
github.com/G-Core/FastEdge-client-sdk-go v0.2.0/go.mod h1:ggyUVhy8/OCMBY4nbm7n9qDoPioROCk4vHhDJq9w7qE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/alecthomas/assert v1.0.0 h1:3XmGh/PSuLzDbK3W2gUbRXwgW5lqPkuqvRgeQ30FI5o=
github.com/alecthomas/assert v1.0.0/go.mod h1:va/d2JC+M7F6s+80kl/R3G7FUiW6JzUO+hPhLyJ36ZY=
Expand All @@ -17,8 +15,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
Expand All @@ -29,10 +25,10 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8=
github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/swag v0.22.9 h1:XX2DssF+mQKM2DHsbgZK74y/zj4mo9I99+89xUmuZCE=
github.com/go-openapi/swag v0.22.9/go.mod h1:3/OXnFfnMAwBD099SwYRk7GD3xOrr1iL7d/XNLXVVwE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang-module/carbon/v2 v2.3.10 h1:C25x4A4UrIch6bisV3j37eU+op5+cp4gw/Fffv5c/FA=
Expand Down Expand Up @@ -72,8 +68,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo=
github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -104,20 +100,22 @@ github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKk
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
Expand Down
62 changes: 35 additions & 27 deletions internal/commands/fastedge/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ uploading binary using "--file <filename>". To load file from stdin, use "-" as
if err != nil {
return err
}
if app.Plan == nil {
return errors.New("plan must be specified")
}
if app.Binary == nil {
file, err := cmd.Flags().GetString("file")
if err != nil {
Expand All @@ -61,7 +58,7 @@ uploading binary using "--file <filename>". To load file from stdin, use "-" as
return fmt.Errorf("adding the app: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("adding the app: %s", string(rsp.Body))
return fmt.Errorf("adding the app: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -124,7 +121,7 @@ uploading binary using "--file <filename>". To load file from stdin, use "-" as
return fmt.Errorf("updating the app: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("updating the app: %s", string(rsp.Body))
return fmt.Errorf("updating the app: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand All @@ -150,27 +147,27 @@ uploading binary using "--file <filename>". To load file from stdin, use "-" as
Short: "Show list of client's apps",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
rsp, err := client.ListAppsWithResponse(context.Background())
rsp, err := client.ListAppsWithResponse(context.Background(), &sdk.ListAppsParams{})
if err != nil {
return fmt.Errorf("getting the list of apps: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("getting the list of apps: %s", string(rsp.Body))
return fmt.Errorf("getting the list of apps: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
fmt.Println(string(rsp.Body))
return nil
}

if len(*rsp.JSON200) == 0 {
if len(rsp.JSON200.Apps) == 0 {
fmt.Printf("you have no apps\n")
return nil
}

table := make([][]string, len(*rsp.JSON200)+1)
table := make([][]string, len(rsp.JSON200.Apps)+1)
table[0] = []string{"ID", "Status", "Name", "Url"}
for i, app := range *rsp.JSON200 {
for i, app := range rsp.JSON200.Apps {
table[i+1] = []string{
strconv.FormatInt(app.Id, 10),
appStatusToString(app.Status),
Expand All @@ -187,8 +184,8 @@ uploading binary using "--file <filename>". To load file from stdin, use "-" as
Use: "show <app_name>",
Aliases: []string{"get"},
Short: "Show app details",
Long: `Show app properties. This command doesn't show app call statisrics.
To see statistics, use "fastedge stat app_calls" and "fastedge stat app_duration"
Long: `Show app properties. This command doesn't show app call statistics.
To see statistics, use "fastedge stats app_calls" and "fastedge stats app_duration"
commands.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -204,7 +201,7 @@ commands.`,
return fmt.Errorf("getting app detail: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("getting app details: %s", string(rsp.Body))
return fmt.Errorf("getting app details: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -247,7 +244,7 @@ commands.`,
return fmt.Errorf("enabling app: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("enabling app: %s", string(rsp.Body))
return fmt.Errorf("enabling app: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -278,7 +275,7 @@ commands.`,
return fmt.Errorf("disabling app: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("disabling app: %s", string(rsp.Body))
return fmt.Errorf("disabling app: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -314,7 +311,7 @@ so if you don't want this to happen, consider disabling the app to keep binary r
return fmt.Errorf("deleting app: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("deleting app: %s", string(rsp.Body))
return fmt.Errorf("deleting app: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -343,7 +340,6 @@ func appPropertiesFlags(cmd *cobra.Command) {
cmd.Flags().String("name", "", "App name")
cmd.Flags().Int64("binary", 0, "Wasm binary id")
cmd.Flags().String("file", "", "Wasm binary filename ('-' means stdin)")
cmd.Flags().String("plan", "", "Plan name")
cmd.Flags().Bool("disabled", false, "Set status to 'disabled'")
cmd.Flags().StringArray("env", nil, "Environment, in name=value format")
cmd.Flags().StringSlice("rsp_headers", nil, "Response headers to add, in name=value format")
Expand All @@ -360,14 +356,6 @@ func parseAppProperties(cmd *cobra.Command) (sdk.App, error) {
app.Name = &name
}

plan, err := cmd.Flags().GetString("plan")
if err != nil {
return app, err
}
if plan != "" {
app.Plan = &plan
}

binID, err := cmd.Flags().GetInt64("binary")
if err != nil {
return app, err
Expand Down Expand Up @@ -447,7 +435,7 @@ func outputMap(m *map[string]string, title string) {
}

func getAppIdByName(appName string) (int64, error) {
idRsp, err := client.GetAppIdByNameWithResponse(context.Background(), appName)
idRsp, err := client.ListAppsWithResponse(context.Background(), &sdk.ListAppsParams{Name: &appName})
if err != nil {
return 0, fmt.Errorf("api response: %w", err)
}
Expand All @@ -457,5 +445,25 @@ func getAppIdByName(appName string) (int64, error) {
if idRsp.JSON200 == nil {
return 0, fmt.Errorf("app '%s' not found", appName)
}
return *idRsp.JSON200, nil
if len(idRsp.JSON200.Apps) != 1 {
return 0, fmt.Errorf("app '%s' not found", appName)
}
return idRsp.JSON200.Apps[0].Id, nil
}

func getAppByName(appName string) (sdk.AppShort, error) {
idRsp, err := client.ListAppsWithResponse(context.Background(), &sdk.ListAppsParams{Name: &appName})
if err != nil {
return sdk.AppShort{}, fmt.Errorf("api response: %w", err)
}
if idRsp.StatusCode() != http.StatusOK {
return sdk.AppShort{}, fmt.Errorf("%s", string(idRsp.Body))
}
if idRsp.JSON200 == nil {
return sdk.AppShort{}, fmt.Errorf("app '%s' not found", appName)
}
if len(idRsp.JSON200.Apps) != 1 {
return sdk.AppShort{}, fmt.Errorf("app '%s' not found", appName)
}
return idRsp.JSON200.Apps[0], nil
}
30 changes: 19 additions & 11 deletions internal/commands/fastedge/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/spf13/cobra"

sdk "github.com/G-Core/FastEdge-client-sdk-go"
"github.com/G-core/gcore-cli/internal/output"
)

Expand All @@ -31,30 +32,31 @@ func binary() *cobra.Command {
Short: "Show list of client's binaries",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
rsp, err := client.ListBinariesWithResponse(context.Background())
rsp, err := client.ListBinariesWithResponse(context.Background(), &sdk.ListBinariesParams{})
if err != nil {
return fmt.Errorf("getting the list of binaries: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("getting the list of binaries: %s", string(rsp.Body))
return fmt.Errorf("getting the list of binaries: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
fmt.Println(string(rsp.Body))
return nil
}

if len(*rsp.JSON200) == 0 {
if len(rsp.JSON200.Binaries) == 0 {
fmt.Printf("you have no binaries\n")
return nil
}

table := make([][]string, len(*rsp.JSON200)+1)
table[0] = []string{"ID", "Status", "Unreferenced since"}
for i, bin := range *rsp.JSON200 {
table := make([][]string, len(rsp.JSON200.Binaries)+1)
table[0] = []string{"ID", "Status", "Name", "Unreferenced since"}
for i, bin := range rsp.JSON200.Binaries {
table[i+1] = []string{
strconv.FormatInt(bin.Id, 10),
binStatusToString(bin.Status),
unrefString(bin.Name),
unrefString(bin.UnrefSince),
}
}
Expand Down Expand Up @@ -105,7 +107,7 @@ If this flag is omitted, file contant is read from stdin.`,
return fmt.Errorf("getting the list of plans: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("getting the list of plans: %s", string(rsp.Body))
return fmt.Errorf("getting the list of plans: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand All @@ -116,8 +118,14 @@ If this flag is omitted, file contant is read from stdin.`,
fmt.Printf(
"Status:\t\t%s\nSource lang:\t%s\n",
binStatusToString(rsp.JSON200.Status),
srcLangToString(rsp.JSON200.Type),
srcLangToString(rsp.JSON200.Source),
)
if rsp.JSON200.Name != nil && *rsp.JSON200.Name != "" {
fmt.Printf("Name:\t\t%s\n", *rsp.JSON200.Name)
}
if rsp.JSON200.Descr != nil && *rsp.JSON200.Descr != "" {
fmt.Printf("Description:\t%s\n", *rsp.JSON200.Descr)
}
if rsp.JSON200.UnrefSince != nil {
fmt.Printf("Unref since:\t%s\n", *rsp.JSON200.UnrefSince)
}
Expand Down Expand Up @@ -146,7 +154,7 @@ If this flag is omitted, file contant is read from stdin.`,
return fmt.Errorf("getting the list of plans: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return fmt.Errorf("getting the list of plans: %s", string(rsp.Body))
return fmt.Errorf("getting the list of plans: %s", extractErrorMessage(rsp.Body))
}

if output.Format(cmd) == output.FmtJSON {
Expand Down Expand Up @@ -184,10 +192,10 @@ func uploadBinary(src string) (int64, error) {
return 0, fmt.Errorf("cannot upload the binary: %w", err)
}
if rsp.StatusCode() != http.StatusOK {
return 0, fmt.Errorf("cannot upload the binary: %s", string(rsp.Body))
return 0, fmt.Errorf("cannot upload the binary: %s", extractErrorMessage(rsp.Body))
}

return *rsp.JSON200, nil
return rsp.JSON200.Id, nil
}

func binStatusToString(s int) string {
Expand Down
Loading