Browse Source

Merge pull request #315 from joyent/sungo/hardware-product-specification-fix

Fix both the uploading of a hardware product's specification and its display
sungo 8 months ago
parent
commit
dc90fb9ee0
3 changed files with 26 additions and 6 deletions
  1. 18 5
      pkg/commands/hardware/hardware.go
  2. 4 0
      pkg/conch/debug.go
  3. 4 1
      pkg/conch/hardware.go

+ 18 - 5
pkg/commands/hardware/hardware.go

@@ -12,6 +12,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"os"
+	"reflect"
 	"text/template"
 
 	"github.com/jawher/mow.cli"
@@ -171,15 +172,27 @@ func getOne(app *cli.Cmd) {
 
 func getOneSpecification(app *cli.Cmd) {
 	app.Action = func() {
-		ret, err := util.API.GetHardwareProduct(ProductUUID)
+		h, err := util.API.GetHardwareProduct(ProductUUID)
 		if err != nil {
 			util.Bail(err)
 		}
-		if ret.Specification == "" {
-			fmt.Println("{}")
-			return
+
+		var specification string
+
+		if h.Specification == nil {
+			specification = "{}"
+		} else if reflect.TypeOf(h.Specification).String() == "string" {
+			specification = h.Specification.(string)
+		} else {
+			j, err := json.Marshal(h.Specification)
+			if err != nil {
+				util.Bail(err)
+			}
+
+			specification = string(j)
 		}
-		fmt.Println(ret.Specification)
+
+		fmt.Println(specification)
 	}
 }
 

+ 4 - 0
pkg/conch/debug.go

@@ -59,5 +59,9 @@ func init() {
 		Indent:                  "    ",
 		SortKeys:                true,
 		DisablePointerAddresses: true,
+		DisableMethods:          true,
+		DisableCapacities:       true,
+		DisablePointerMethods:   true,
+		SpewKeys:                true,
 	}
 }

+ 4 - 1
pkg/conch/hardware.go

@@ -10,6 +10,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"net/url"
+	"reflect"
 
 	"github.com/joyent/conch-shell/pkg/conch/uuid"
 )
@@ -48,11 +49,13 @@ func (c *Conch) SaveHardwareProduct(h *HardwareProduct) error {
 	}
 
 	var specification string
+
 	if h.Specification == nil {
 		specification = ""
+	} else if reflect.TypeOf(h.Specification).String() == "string" {
+		specification = h.Specification.(string)
 	} else {
 		j, err := json.Marshal(h.Specification)
-
 		if err != nil {
 			return err
 		}