mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 20:12:25 +00:00
add optional config preview with confirmation
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package hooks
|
package hooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -185,6 +186,29 @@ func Init6Hook(cs *corestate.CoreState, x *app.AppX) {
|
|||||||
}
|
}
|
||||||
x.Config.Conf.Log.Level = &logs.Levels.Fallback
|
x.Config.Conf.Log.Level = &logs.Levels.Fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *x.Config.Conf.Node.ShowConfig {
|
||||||
|
fmt.Printf("Configuration from %s:\n", x.Config.CMDLine.Run.ConfigPath)
|
||||||
|
x.Config.Print(x.Config.Conf)
|
||||||
|
|
||||||
|
fmt.Printf("Environment:\n")
|
||||||
|
x.Config.Print(x.Config.Env)
|
||||||
|
ok := true
|
||||||
|
|
||||||
|
fmt.Printf("%s (%s/%s): ", "Is that ok?", logs.SetBrightGreen("Y"), logs.SetBrightRed("n"))
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
input, _ := reader.ReadString('\n')
|
||||||
|
input = strings.TrimSpace(strings.ToLower(input))
|
||||||
|
|
||||||
|
ok = input == "" || input == "y" || input == "yes"
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
_ = run_manager.Clean()
|
||||||
|
x.Log.Fatalf("Cancel launch")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x.Log.Printf("Starting \"%s\" node", *x.Config.Conf.Node.Name)
|
x.Log.Printf("Starting \"%s\" node", *x.Config.Conf.Node.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func RunHook(ctx context.Context, cs *corestate.CoreState, x *app.AppX) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
session_manager.StartCleanup(5 * time.Minute)
|
session_manager.StartCleanup(5 * time.Second)
|
||||||
|
|
||||||
if *x.Config.Conf.Updates.UpdatesEnabled {
|
if *x.Config.Conf.Updates.UpdatesEnabled {
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ func (c *Compositor) LoadConf(path string) error {
|
|||||||
// defaults
|
// defaults
|
||||||
v.SetDefault("node.name", "noname")
|
v.SetDefault("node.name", "noname")
|
||||||
v.SetDefault("node.mode", "dev")
|
v.SetDefault("node.mode", "dev")
|
||||||
|
v.SetDefault("node.show_config", "false")
|
||||||
v.SetDefault("node.com_dir", "./com/")
|
v.SetDefault("node.com_dir", "./com/")
|
||||||
v.SetDefault("http_server.address", "0.0.0.0")
|
v.SetDefault("http_server.address", "0.0.0.0")
|
||||||
v.SetDefault("http_server.port", "8080")
|
v.SetDefault("http_server.port", "8080")
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type Conf struct {
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
Mode *string `mapstructure:"mode"`
|
Mode *string `mapstructure:"mode"`
|
||||||
Name *string `mapstructure:"name"`
|
Name *string `mapstructure:"name"`
|
||||||
|
ShowConfig *bool `mapstructure:"show_config"`
|
||||||
ComDir *string `mapstructure:"com_dir"`
|
ComDir *string `mapstructure:"com_dir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
58
internal/engine/config/print.go
Normal file
58
internal/engine/config/print.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Compositor) Print(v any) {
|
||||||
|
c.printConfig(v, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Compositor) printConfig(v any, prefix string) {
|
||||||
|
val := reflect.ValueOf(v)
|
||||||
|
if val.Kind() == reflect.Ptr {
|
||||||
|
val = val.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
typ := val.Type()
|
||||||
|
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
field := val.Field(i)
|
||||||
|
fieldType := typ.Field(i)
|
||||||
|
|
||||||
|
fieldName := fieldType.Name
|
||||||
|
if tag, ok := fieldType.Tag.Lookup("mapstructure"); ok {
|
||||||
|
if tag != "" {
|
||||||
|
fieldName = tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if field.Kind() == reflect.Ptr {
|
||||||
|
if field.IsNil() {
|
||||||
|
fmt.Printf("%s%s: <nil>\n", prefix, fieldName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
field = field.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if field.Kind() == reflect.Struct {
|
||||||
|
if field.Type() == reflect.TypeOf(time.Duration(0)) {
|
||||||
|
duration := field.Interface().(time.Duration)
|
||||||
|
fmt.Printf("%s%s: %s\n", prefix, fieldName, duration.String())
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s%s:\n", prefix, fieldName)
|
||||||
|
c.printConfig(field.Addr().Interface(), prefix+" ")
|
||||||
|
}
|
||||||
|
} else if field.Kind() == reflect.Slice {
|
||||||
|
fmt.Printf("%s%s: %v\n", prefix, fieldName, field.Interface())
|
||||||
|
} else {
|
||||||
|
value := field.Interface()
|
||||||
|
if field.Kind() == reflect.String {
|
||||||
|
value = fmt.Sprintf("\"%s\"", value)
|
||||||
|
}
|
||||||
|
fmt.Printf("%s%s: %v\n", prefix, fieldName, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user