Skip to content

Commit

Permalink
Make table and json output consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
OmSaran committed Feb 22, 2023
1 parent 00d5b2a commit c721b05
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/minikube/cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var serviceListCmd = &cobra.Command{
case "table":
printServicesTable(serviceURLs, co)
case "json":
printServicesJSON(serviceURLs)
printServicesJSON(serviceURLs, co)
default:
exit.Message(reason.Usage, fmt.Sprintf("invalid output format: %s. Valid values: 'table', 'json'", output))
}
Expand Down Expand Up @@ -85,8 +85,20 @@ func printServicesTable(serviceURLs service.URLs, co mustload.ClusterController)
service.PrintServiceList(os.Stdout, data)
}

func printServicesJSON(serviceURLs service.URLs) {
jsonString, _ := json.Marshal(serviceURLs)
func printServicesJSON(serviceURLs service.URLs, co mustload.ClusterController) {
processedServiceURLs := serviceURLs

if runtime.GOOS == "darwin" && co.Config.Driver == oci.Docker {
// To ensure we don't modify the original serviceURLs
processedServiceURLs = make(service.URLs, len(serviceURLs))
copy(processedServiceURLs, serviceURLs)

for idx := range processedServiceURLs {
processedServiceURLs[idx].URLs = make([]string, 0)
}
}

jsonString, _ := json.Marshal(processedServiceURLs)
os.Stdout.Write(jsonString)
}

Expand Down

0 comments on commit c721b05

Please sign in to comment.