Skip to content

Commit

Permalink
suggestion: use map[string]any and a small util function
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Dec 20, 2023
1 parent df7e863 commit 7240902
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 1 addition & 6 deletions internal/cmd/certificate/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hetznercloud/cli/internal/hcapi2"
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

var CreateCmd = base.CreateCmd{
Expand Down Expand Up @@ -57,11 +56,7 @@ var CreateCmd = base.CreateCmd{
if err != nil {
return nil, nil, err
}
return cert, struct {
Certificate schema.Certificate `json:"certificate"`
}{
Certificate: hcloud.SchemaFromCertificate(cert),
}, nil
return cert, util.WrapSchema("certificate", hcloud.SchemaFromCertificate(cert)), nil
},
}

Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ func DescribeYAML(object interface{}) error {
return enc.Encode(object)
}

// WrapSchema return a map wrapping the schema (value) in a dict (`{ key: value }`).
//
// Used to reduce boilerplate.
func WrapSchema(key string, value any) map[string]any {
return map[string]any{key: value}
}

// ValidateRequiredFlags ensures that flags has values for all flags with
// the passed names.
//
Expand Down

0 comments on commit 7240902

Please sign in to comment.