feat: CLI use multiselect for list(string) (#6631)

* feat: CLI use multiselect for list(string)

* fix

* select ui tests

* cli test

* Fix

* Fix
This commit is contained in:
Marcin Tojek
2023-03-16 17:17:48 +01:00
committed by GitHub
parent 95177ad0e5
commit 1f9ae15409
6 changed files with 199 additions and 6 deletions
+19 -4
View File
@@ -1,6 +1,8 @@
package cli
import (
"encoding/json"
"fmt"
"os"
"github.com/spf13/cobra"
@@ -15,19 +17,32 @@ import (
// Throws an error if the file name is empty.
func createParameterMapFromFile(parameterFile string) (map[string]string, error) {
if parameterFile != "" {
parameterMap := make(map[string]string)
parameterFileContents, err := os.ReadFile(parameterFile)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(parameterFileContents, &parameterMap)
mapStringInterface := make(map[string]interface{})
err = yaml.Unmarshal(parameterFileContents, &mapStringInterface)
if err != nil {
return nil, err
}
parameterMap := map[string]string{}
for k, v := range mapStringInterface {
switch val := v.(type) {
case string, bool, int:
parameterMap[k] = fmt.Sprintf("%v", val)
case []interface{}:
b, err := json.Marshal(&val)
if err != nil {
return nil, err
}
parameterMap[k] = string(b)
default:
return nil, xerrors.Errorf("invalid parameter type: %T", v)
}
}
return parameterMap, nil
}