Adding output result to onuimage commands

Change-Id: I136fc499c0e954982a1de14aa9d504c1d6e7920c
diff --git a/VERSION b/VERSION
index ec70f75..400084b 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.6.6
+1.6.7
diff --git a/internal/pkg/commands/devices.go b/internal/pkg/commands/devices.go
index 073cd66..dd687a1 100644
--- a/internal/pkg/commands/devices.go
+++ b/internal/pkg/commands/devices.go
@@ -285,6 +285,7 @@
 }
 
 type OnuDownloadImage struct {
+	ListOutputOptions
 	Args struct {
 		ImageVersion      string     `positional-arg-name:"IMAGE_VERSION" required:"yes"`
 		Url               string     `positional-arg-name:"IMAGE_URL" required:"yes"`
@@ -297,6 +298,7 @@
 }
 
 type OnuActivateImage struct {
+	ListOutputOptions
 	Args struct {
 		ImageVersion    string     `positional-arg-name:"IMAGE_VERSION" required:"yes"`
 		CommitOnSuccess bool       `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
@@ -305,6 +307,7 @@
 }
 
 type OnuAbortUpgradeImage struct {
+	ListOutputOptions
 	Args struct {
 		ImageVersion string     `positional-arg-name:"IMAGE_VERSION" required:"yes"`
 		IDs          []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
@@ -312,6 +315,7 @@
 }
 
 type OnuCommitImage struct {
+	ListOutputOptions
 	Args struct {
 		ImageVersion string     `positional-arg-name:"IMAGE_VERSION" required:"yes"`
 		IDs          []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
@@ -1541,11 +1545,23 @@
 		CommitOnSuccess:   options.Args.CommitOnSuccess,
 	}
 
-	_, err = client.DownloadImageToDevice(ctx, &downloadImage)
+	deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
 	if err != nil {
 		return err
 	}
 
+	outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
+	// Make sure json output prints an empty list, not "null"
+	if deviceImageResp.DeviceImageStates == nil {
+		deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
+	}
+	result := CommandResult{
+		Format:    format.Format(outputFormat),
+		OutputAs:  toOutputType(options.OutputAs),
+		NameLimit: options.NameLimit,
+		Data:      deviceImageResp.DeviceImageStates,
+	}
+	GenerateOutput(&result)
 	return nil
 
 }
@@ -1575,11 +1591,24 @@
 		CommitOnSuccess: options.Args.CommitOnSuccess,
 	}
 
-	_, err = client.ActivateImage(ctx, &downloadImage)
+	deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
 	if err != nil {
 		return err
 	}
 
+	outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
+	// Make sure json output prints an empty list, not "null"
+	if deviceImageResp.DeviceImageStates == nil {
+		deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
+	}
+	result := CommandResult{
+		Format:    format.Format(outputFormat),
+		OutputAs:  toOutputType(options.OutputAs),
+		NameLimit: options.NameLimit,
+		Data:      deviceImageResp.DeviceImageStates,
+	}
+	GenerateOutput(&result)
+
 	return nil
 
 }
@@ -1608,11 +1637,24 @@
 		Version:  options.Args.ImageVersion,
 	}
 
-	_, err = client.AbortImageUpgradeToDevice(ctx, &downloadImage)
+	deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
 	if err != nil {
 		return err
 	}
 
+	outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
+	// Make sure json output prints an empty list, not "null"
+	if deviceImageResp.DeviceImageStates == nil {
+		deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
+	}
+	result := CommandResult{
+		Format:    format.Format(outputFormat),
+		OutputAs:  toOutputType(options.OutputAs),
+		NameLimit: options.NameLimit,
+		Data:      deviceImageResp.DeviceImageStates,
+	}
+	GenerateOutput(&result)
+
 	return nil
 
 }
@@ -1640,11 +1682,24 @@
 		Version:  options.Args.ImageVersion,
 	}
 
-	_, err = client.CommitImage(ctx, &downloadImage)
+	deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
 	if err != nil {
 		return err
 	}
 
+	outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
+	// Make sure json output prints an empty list, not "null"
+	if deviceImageResp.DeviceImageStates == nil {
+		deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
+	}
+	result := CommandResult{
+		Format:    format.Format(outputFormat),
+		OutputAs:  toOutputType(options.OutputAs),
+		NameLimit: options.NameLimit,
+		Data:      deviceImageResp.DeviceImageStates,
+	}
+	GenerateOutput(&result)
+
 	return nil
 
 }