Skip to content

Commit

Permalink
fix: list outputs null instead of empty array when listing in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Oct 24, 2023
1 parent 9a0487a commit a3997e7
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/certificate/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var certSchemas []schema.Certificate
certSchemas := make([]schema.Certificate, 0, len(resources))
for _, resource := range resources {
cert := resource.(*hcloud.Certificate)
certSchema := schema.Certificate{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/datacenter/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var dcSchemas []schema.Datacenter
dcSchemas := make([]schema.Datacenter, 0, len(resources))
for _, resource := range resources {
dc := resource.(*hcloud.Datacenter)
dcSchemas = append(dcSchemas, util.DatacenterToSchema(*dc))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/firewall/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var firewallSchemas []schema.Firewall
firewallSchemas := make([]schema.Firewall, 0, len(resources))
for _, resource := range resources {
firewall := resource.(*hcloud.Firewall)
firewallSchema := schema.Firewall{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/floatingip/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var floatingIPSchemas []schema.FloatingIP
floatingIPSchemas := make([]schema.FloatingIP, 0, len(resources))
for _, resource := range resources {
floatingIP := resource.(*hcloud.FloatingIP)
floatingIPSchema := schema.FloatingIP{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var imageSchemas []schema.Image
imageSchemas := make([]schema.Image, 0, len(resources))
for _, resource := range resources {
image := resource.(*hcloud.Image)
imageSchemas = append(imageSchemas, util.ImageToSchema(*image))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iso/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var isoSchemas []schema.ISO
isoSchemas := make([]schema.ISO, 0, len(resources))
for _, resource := range resources {
iso := resource.(*hcloud.ISO)
isoSchemas = append(isoSchemas, util.ISOToSchema(*iso))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/loadbalancer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var loadBalancerSchemas []schema.LoadBalancer
loadBalancerSchemas := make([]schema.LoadBalancer, 0, len(resources))
for _, resource := range resources {
loadBalancer := resource.(*hcloud.LoadBalancer)
loadBalancerSchema := schema.LoadBalancer{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/loadbalancertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var loadBalancerTypeSchemas []schema.LoadBalancerType
loadBalancerTypeSchemas := make([]schema.LoadBalancerType, 0, len(resources))
for _, resource := range resources {
loadBalancerType := resource.(*hcloud.LoadBalancerType)
loadBalancerTypeSchemas = append(loadBalancerTypeSchemas, util.LoadBalancerTypeToSchema(*loadBalancerType))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/location/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var locationSchemas []schema.Location
locationSchemas := make([]schema.Location, 0, len(resources))
for _, resource := range resources {
location := resource.(*hcloud.Location)
locationSchemas = append(locationSchemas, util.LocationToSchema(*location))
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/network/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ var ListCmd = base.ListCmd{
return util.Age(network.Created, time.Now())
}))
},

JSONSchema: func(resources []interface{}) interface{} {
var networkSchemas []schema.Network
networkSchemas := make([]schema.Network, 0, len(resources))
for _, resource := range resources {
network := resource.(*hcloud.Network)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/placementgroup/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var placementGroupSchemas []schema.PlacementGroup
placementGroupSchemas := make([]schema.PlacementGroup, 0, len(resources))
for _, resource := range resources {
placementGroup := resource.(*hcloud.PlacementGroup)
placementGroupSchema := schema.PlacementGroup{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/primaryip/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var primaryIPsSchema []schema.PrimaryIP
primaryIPsSchema := make([]schema.PrimaryIP, 0, len(resources))
for _, resource := range resources {
primaryIP := resource.(*hcloud.PrimaryIP)
var dnsPtrs []hcloud.PrimaryIPDNSPTR
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var serversSchema []schema.Server
serversSchema := make([]schema.Server, 0, len(resources))
for _, resource := range resources {
server := resource.(*hcloud.Server)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/servertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var serverTypeSchemas []schema.ServerType
serverTypeSchemas := make([]schema.ServerType, 0, len(resources))
for _, resource := range resources {
serverType := resource.(*hcloud.ServerType)
serverTypeSchemas = append(serverTypeSchemas, util.ServerTypeToSchema(*serverType))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/sshkey/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var sshKeySchemas []schema.SSHKey
sshKeySchemas := make([]schema.SSHKey, 0, len(resources))
for _, resource := range resources {
sshKey := resource.(*hcloud.SSHKey)
sshKeySchema := schema.SSHKey{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/volume/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var ListCmd = base.ListCmd{
},

JSONSchema: func(resources []interface{}) interface{} {
var volumesSchema []schema.Volume
volumesSchema := make([]schema.Volume, 0, len(resources))
for _, resource := range resources {
volume := resource.(*hcloud.Volume)
volumeSchema := schema.Volume{
Expand Down

0 comments on commit a3997e7

Please sign in to comment.