mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
Feat: print complex values in addon parameters (#4309)
* Feat: support nested parameters in addon parameters Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: show all params Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: handle any addon parameters Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Refactor: add a error check on json marshell Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: fix tests Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
This commit is contained in:
+10
-9
@@ -18,6 +18,7 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -753,12 +754,13 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind
|
||||
}
|
||||
required := required[propKey]
|
||||
|
||||
// Extra indentation on nested objects
|
||||
addedIndent := addIndent(indent)
|
||||
|
||||
var currentValue string
|
||||
thisParam, hasParam := currentParams[propKey]
|
||||
if hasParam {
|
||||
// Only show default parameter when it is a string, int, float, or bool
|
||||
// We don't care about object's default values (they have no defaults anyway).
|
||||
currentValue = fmt.Sprint(thisParam)
|
||||
currentValue = fmt.Sprintf("%#v", thisParam)
|
||||
switch thisParam.(type) {
|
||||
case int:
|
||||
case int64:
|
||||
@@ -768,13 +770,12 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind
|
||||
case string:
|
||||
case bool:
|
||||
default:
|
||||
currentValue = ""
|
||||
if js, err := json.MarshalIndent(thisParam, "", " "); err == nil {
|
||||
currentValue = strings.ReplaceAll(string(js), "\n", "\n\t "+addedIndent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extra indentation on nested objects
|
||||
addedIndent := addIndent(indent)
|
||||
|
||||
// Header: addon: description
|
||||
ret += addedIndent
|
||||
ret += color.New(color.FgCyan).Sprintf("-> ")
|
||||
@@ -783,8 +784,8 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind
|
||||
|
||||
// Show current value
|
||||
if currentValue != "" {
|
||||
ret += addIndent(indent)
|
||||
ret += "\tcurrent: " + color.New(color.FgGreen).Sprintf("%#v\n", currentValue)
|
||||
ret += addedIndent
|
||||
ret += "\tcurrent: " + color.New(color.FgGreen).Sprintf("%s\n", currentValue)
|
||||
}
|
||||
// Show default value
|
||||
if defaultValue != "" {
|
||||
|
||||
Reference in New Issue
Block a user