mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-31 04:30:44 +00:00
Added map to to_string and tabs to config_show
This commit is contained in:
+24
-8
@@ -12,12 +12,13 @@ func aptlyConfigShow(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
config := context.Config()
|
config := context.Config()
|
||||||
|
|
||||||
fmt.Println(to_string(reflect.ValueOf(config).Elem()))
|
fmt.Println(to_string(reflect.ValueOf(config).Elem(), 0))
|
||||||
return err
|
|
||||||
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func to_string(v reflect.Value) string {
|
func to_string(v reflect.Value, tabs int) string {
|
||||||
|
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
|
|
||||||
@@ -28,19 +29,26 @@ func to_string(v reflect.Value) 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)))
|
str_slice = append(str_slice, to_string(v.Index(i), tabs))
|
||||||
}
|
}
|
||||||
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, typ.Field(i).Name+": "+to_string(v.Field(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, make_tabs(tabs)+"}")
|
||||||
|
return strings.Join(str_slice, "\n")
|
||||||
|
case reflect.Map:
|
||||||
|
var str_slice []string
|
||||||
|
str_slice = append(str_slice, "")
|
||||||
|
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, make_tabs(tabs)+"}")
|
||||||
return strings.Join(str_slice, "\n")
|
return strings.Join(str_slice, "\n")
|
||||||
//case reflect.Map:
|
|
||||||
// var str_slice []string
|
|
||||||
|
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
return v.String()
|
return v.String()
|
||||||
}
|
}
|
||||||
@@ -48,6 +56,14 @@ func to_string(v reflect.Value) string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyConfigShow,
|
Run: aptlyConfigShow,
|
||||||
|
|||||||
Reference in New Issue
Block a user