这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/apps/getapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var GetCmd = &cobra.Command{
return err
}
// print the item
return apiclient.PrettyPrint(outBytes)
return apiclient.PrettyPrint("json", outBytes)
}

_, err = apps.ListApps(productName)
Expand Down
2 changes: 1 addition & 1 deletion internal/apiclient/clifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func GetPreferences() (err error) {
return err
}

return PrettyPrint(output)
return PrettyPrint("json", output)
}

// WritePreferencesFile
Expand Down
19 changes: 11 additions & 8 deletions internal/apiclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,19 @@ func HttpClient(params ...string) (respBody []byte, err error) {
}

// PrettyPrint method prints formatted json
func PrettyPrint(body []byte) error {
func PrettyPrint(contentType string, body []byte) error {
if GetCmdPrintHttpResponseSetting() && ClientPrintHttpResponse.Get() {
var prettyJSON bytes.Buffer
err := json.Indent(&prettyJSON, body, "", "\t")
if err != nil {
clilog.Error.Println("error parsing response: ", err)
return err
}
//pretty print only json responses with body
if strings.Contains(contentType, "json") && len(body) > 0 {
err := json.Indent(&prettyJSON, body, "", "\t")
if err != nil {
clilog.Error.Println("error parsing response: ", err)
return err
}

clilog.HttpResponse.Println(prettyJSON.String())
clilog.HttpResponse.Println(prettyJSON.String())
}
}
return nil
}
Expand Down Expand Up @@ -438,7 +441,7 @@ func handleResponse(resp *http.Response) (respBody []byte, err error) {
return nil, errors.New(getErrorMessage(resp.StatusCode))
}

return respBody, PrettyPrint(respBody)
return respBody, PrettyPrint(resp.Header.Get("Content-Type"), respBody)
}

func getErrorMessage(statusCode int) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func GetAllDeployments() (respBody []byte, err error) {
payload := "{" + strings.Join(deployments, ",") + "}"

apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
err = apiclient.PrettyPrint([]byte(payload))
err = apiclient.PrettyPrint("json", []byte(payload))
return []byte(payload), err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/client/operations/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func filterOperation(respBody []byte, state string, completeState OperationCompl
}

if apiclient.GetPrintOutput() {
apiclient.PrettyPrint(operationsRespBody)
apiclient.PrettyPrint("json", operationsRespBody)
}
return operationsRespBody, nil
}
2 changes: 1 addition & 1 deletion internal/client/products/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func ListFilter(filter map[string]string) (respBody []byte, err error) {

respBody, err = json.Marshal(outprds)
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
_ = apiclient.PrettyPrint(respBody)
_ = apiclient.PrettyPrint("json", respBody)

return respBody, err
}
Expand Down