Skip to content

Commit dda30ca

Browse files
author
Tim Middleton
authored
Code cleanup for json and jsonpath output (#243)
* Code cleanup for json and jsonpath output * Bump CLI version to 1.8.0
1 parent cc6a2d9 commit dda30ca

File tree

13 files changed

+309
-407
lines changed

13 files changed

+309
-407
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# ======================================================================================================================
1616

1717
# The version of the CLI being build - this should be a valid SemVer format
18-
VERSION ?= 1.7.3
18+
VERSION ?= 1.8.0
1919
MILESTONE ?=
2020
SHELL := /bin/bash
2121

pkg/cmd/cache.go

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ name is specified then all services are queried.`,
537537
for {
538538
var viewServicesSummary = config.ServicesSummaries{}
539539

540-
if strings.Contains(OutputFormat, constants.JSONPATH) || OutputFormat == constants.JSON {
540+
if isJSONPathOrJSON() {
541541
data, err := dataFetcher.GetViewsSummaryJSONAllServices()
542542
if err != nil {
543543
return err
@@ -621,7 +621,6 @@ func getCacheDetails(cmd *cobra.Command, args []string, displayType string) erro
621621
cacheResult []byte
622622
cacheDetails = config.CacheDetails{}
623623
cachePartitionDetails = config.CachePartitionDetails{}
624-
result string
625624
)
626625

627626
if displayType == partitionDisplayType {
@@ -637,41 +636,35 @@ func getCacheDetails(cmd *cobra.Command, args []string, displayType string) erro
637636
return fmt.Errorf(cannotFindCache, cacheName, serviceName)
638637
}
639638

640-
if strings.Contains(OutputFormat, constants.JSONPATH) {
641-
result, err = utils.GetJSONPathResults(cacheResult, OutputFormat)
642-
if err != nil {
643-
return err
644-
}
645-
cmd.Println(result)
646-
} else if OutputFormat == constants.JSON {
647-
cmd.Println(string(cacheResult))
639+
if isJSONPathOrJSON() {
640+
return processJSONOutput(cmd, cacheResult)
641+
}
642+
643+
if displayType == partitionDisplayType {
644+
err = json.Unmarshal(cacheResult, &cachePartitionDetails)
648645
} else {
649-
if displayType == partitionDisplayType {
650-
err = json.Unmarshal(cacheResult, &cachePartitionDetails)
651-
} else {
652-
err = json.Unmarshal(cacheResult, &cacheDetails)
653-
}
654-
if err != nil {
655-
return utils.GetError("unable to unmarshall cache result", err)
656-
}
646+
err = json.Unmarshal(cacheResult, &cacheDetails)
647+
}
648+
if err != nil {
649+
return utils.GetError("unable to unmarshall cache result", err)
650+
}
657651

658-
printWatchHeader(cmd)
659-
cmd.Println(FormatCurrentCluster(connection))
652+
printWatchHeader(cmd)
653+
cmd.Println(FormatCurrentCluster(connection))
660654

661-
if displayType != partitionDisplayType {
662-
cmd.Printf("Cache: %s\n\n", args[0])
663-
}
655+
if displayType != partitionDisplayType {
656+
cmd.Printf("Cache: %s\n\n", args[0])
657+
}
664658

665-
if displayType == access {
666-
cmd.Println(FormatCacheDetailsSizeAndAccess(cacheDetails.Details))
667-
} else if displayType == "index" {
668-
cmd.Println(FormatCacheIndexDetails(cacheDetails.Details))
669-
} else if displayType == storage {
670-
cmd.Println(FormatCacheDetailsStorage(cacheDetails.Details))
671-
} else if displayType == partitionDisplayType {
672-
cmd.Printf("Cache: %s\n", args[0])
673-
cmd.Println(FormatCachePartitions(cachePartitionDetails.Details, cacheSummary))
674-
}
659+
if displayType == access {
660+
cmd.Println(FormatCacheDetailsSizeAndAccess(cacheDetails.Details))
661+
} else if displayType == "index" {
662+
cmd.Println(FormatCacheIndexDetails(cacheDetails.Details))
663+
} else if displayType == storage {
664+
cmd.Println(FormatCacheDetailsStorage(cacheDetails.Details))
665+
} else if displayType == partitionDisplayType {
666+
cmd.Printf("Cache: %s\n", args[0])
667+
cmd.Println(FormatCachePartitions(cachePartitionDetails.Details, cacheSummary))
675668
}
676669

677670
// check to see if we should exit if we are not watching

0 commit comments

Comments
 (0)