mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-30 04:20:53 +00:00
Config_show prints out strings,structs,ints,bools
More development for aptly config show
This commit is contained in:
+38
-3
@@ -1,15 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
import "github.com/smira/commander"
|
||||
|
||||
func aptlyConfigShow(cmd *commander.Command, args []string) error {
|
||||
|
||||
config := context.Config()
|
||||
|
||||
fmt.Printf("RootDir: %s")
|
||||
fmt.Println(to_string(reflect.ValueOf(config).Elem()))
|
||||
return err
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func to_string(v reflect.Value) string {
|
||||
|
||||
switch v.Kind() {
|
||||
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.FormatInt(v.Int(), 10)
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(v.Bool())
|
||||
case reflect.Slice:
|
||||
var str_slice []string
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
str_slice = append(str_slice, to_string(v.Index(i)))
|
||||
}
|
||||
return strings.Join(str_slice, ", ")
|
||||
case reflect.Struct:
|
||||
var str_slice []string
|
||||
typ := reflect.TypeOf(v.Interface())
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
str_slice = append(str_slice, typ.Field(i).Name+": "+to_string(v.Field(i)))
|
||||
}
|
||||
return strings.Join(str_slice, "\n")
|
||||
//case reflect.Map:
|
||||
// var str_slice []string
|
||||
|
||||
case reflect.String:
|
||||
return v.String()
|
||||
}
|
||||
return ""
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user