mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-02 04:50:49 +00:00
Config show now outputs a clean data structure
This commit is contained in:
+16
-19
@@ -5,20 +5,26 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
import "github.com/smira/commander"
|
|
||||||
|
|
||||||
func aptlyConfigShow(cmd *commander.Command, args []string) error {
|
func aptlyConfigShow(cmd *commander.Command, args []string) error {
|
||||||
|
|
||||||
config := context.Config()
|
config := context.Config()
|
||||||
|
|
||||||
fmt.Println(to_string(reflect.ValueOf(config).Elem(), 0))
|
config_to_string := toString(reflect.ValueOf(config).Elem())
|
||||||
|
|
||||||
|
if config_to_string == "" {
|
||||||
|
return fmt.Errorf("Error processing configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(config_to_string)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func to_string(v reflect.Value, tabs int) string {
|
func toString(v reflect.Value) string {
|
||||||
|
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
|
|
||||||
@@ -29,39 +35,30 @@ func to_string(v reflect.Value, tabs int) string {
|
|||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
var str_slice []string
|
var str_slice []string
|
||||||
for i := 0; i < v.Len(); i++ {
|
for i := 0; i < v.Len(); i++ {
|
||||||
str_slice = append(str_slice, to_string(v.Index(i), tabs))
|
str_slice = append(str_slice, toString(v.Index(i)))
|
||||||
}
|
}
|
||||||
return strings.Join(str_slice, ", ")
|
return strings.Join(str_slice, ", ")
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
var str_slice []string
|
var str_slice []string
|
||||||
typ := reflect.TypeOf(v.Interface())
|
typ := reflect.TypeOf(v.Interface())
|
||||||
//str_slice = append(str_slice, make_tabs(tabs)+"{")
|
|
||||||
for i := 0; i < typ.NumField(); i++ {
|
for i := 0; i < typ.NumField(); i++ {
|
||||||
str_slice = append(str_slice, make_tabs(tabs)+typ.Field(i).Name+": "+to_string(v.Field(i), tabs+1))
|
str_slice = append(str_slice, typ.Field(i).Name+": "+toString(v.Field(i)))
|
||||||
}
|
}
|
||||||
//str_slice = append(str_slice, make_tabs(tabs)+"}")
|
|
||||||
return strings.Join(str_slice, "\n")
|
return strings.Join(str_slice, "\n")
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
var str_slice []string
|
var str_slice []string
|
||||||
str_slice = append(str_slice, "")
|
str_slice = append(str_slice, "")
|
||||||
for _, key := range v.MapKeys() {
|
for _, key := range v.MapKeys() {
|
||||||
str_slice = append(str_slice, make_tabs(tabs)+"- "+to_string(key, tabs)+":\n"+to_string(v.MapIndex(key), tabs+1))
|
str_slice = append(str_slice, "- "+toString(key)+":\n"+toString(v.MapIndex(key)))
|
||||||
}
|
}
|
||||||
//str_slice = append(str_slice, make_tabs(tabs)+"}")
|
|
||||||
return strings.Join(str_slice, "\n")
|
return strings.Join(str_slice, "\n")
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
return v.String()
|
return v.String()
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func make_tabs(tabs int) string {
|
|
||||||
str := ""
|
|
||||||
for i := 0; i < tabs; i++ {
|
|
||||||
str += "\t"
|
|
||||||
}
|
|
||||||
return str
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCmdConfigShow() *commander.Command {
|
func makeCmdConfigShow() *commander.Command {
|
||||||
|
|||||||
Reference in New Issue
Block a user