diff --git a/go.mod b/go.mod index 30f628170d..2d3f3ae2a3 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/mattn/go-colorable v0.1.4 github.com/mattn/go-isatty v0.0.11 github.com/pkg/errors v0.9.1 // indirect - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200610085115-f7eab704fcbe + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65 github.com/sergi/go-diff v1.0.0 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 8aef802592..b9778f367f 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,10 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200608155405-2c0edbf44628 github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200608155405-2c0edbf44628/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200610085115-f7eab704fcbe h1:sDuQ3A081/brDcQr5AFz8JwX9Od1v8w3sW/L/g25UfY= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200610085115-f7eab704fcbe/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2 h1:Pbot5MmWbvw0K2HqVjcJo3+J7l6vGbB852f7CNeKfyQ= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622145638-4884584cccc2/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65 h1:QhG9tN5aUb20f6W8ecoH9XZwa4+0sg6ovBZrYKkp7C0= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200622150328-6c000c76bc65/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= diff --git a/internal/core/arg_specs.go b/internal/core/arg_specs.go index cf41c4df30..993c99ee9b 100644 --- a/internal/core/arg_specs.go +++ b/internal/core/arg_specs.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/scaleway/scaleway-sdk-go/scw" + "github.com/scaleway/scaleway-sdk-go/validation" ) type ArgSpecs []*ArgSpec @@ -109,6 +110,15 @@ func ZoneArgSpec(zones ...scw.Zone) *ArgSpec { Name: "zone", Short: "Zone to target. If none is passed will use default zone from the config", EnumValues: enumValues, + ValidateFunc: func(argSpec *ArgSpec, value interface{}) error { + if validation.IsZone(value.(scw.Zone).String()) { + return nil + } + return &CliError{ + Err: fmt.Errorf("invalid zone %s", value), + Hint: "Zone format should look like XX-XXX-X (e.g. fr-par-1)", + } + }, Default: func(ctx context.Context) (value string, doc string) { client := ExtractClient(ctx) zone, _ := client.GetDefaultZone() @@ -126,6 +136,15 @@ func RegionArgSpec(regions ...scw.Region) *ArgSpec { Name: "region", Short: "Region to target. If none is passed will use default region from the config", EnumValues: enumValues, + ValidateFunc: func(argSpec *ArgSpec, value interface{}) error { + if validation.IsRegion(value.(scw.Region).String()) { + return nil + } + return &CliError{ + Err: fmt.Errorf("invalid region %s", value), + Hint: "Region format should look like XX-XXX (e.g. fr-par)", + } + }, Default: func(ctx context.Context) (value string, doc string) { client := ExtractClient(ctx) region, _ := client.GetDefaultRegion() diff --git a/internal/namespaces/account/v2alpha1/testdata/test-ssh-key-add-command-simple.golden b/internal/namespaces/account/v2alpha1/testdata/test-ssh-key-add-command-simple.golden index 16bf1cb96d..c61aaab236 100644 --- a/internal/namespaces/account/v2alpha1/testdata/test-ssh-key-add-command-simple.golden +++ b/internal/namespaces/account/v2alpha1/testdata/test-ssh-key-add-command-simple.golden @@ -10,6 +10,7 @@ creation-info.address - creation-info.user-agent - creation-info.country-code - organization-id 951df375-e094-4d26-97c1-ba548eeb9c42 +project-id - 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 { "id": "29e8be8f-ad33-4299-b816-72b8d45b2fb0", @@ -23,5 +24,6 @@ organization-id 951df375-e094-4d26-97c1-ba548eeb9c42 "user_agent": "", "country_code": "" }, - "organization_id": "951df375-e094-4d26-97c1-ba548eeb9c42" + "organization_id": "951df375-e094-4d26-97c1-ba548eeb9c42", + "project_id": "" }