✨ Parse config overrides on cli
This commit is contained in:
parent
40f9518611
commit
25f5c37243
8 changed files with 169 additions and 32 deletions
|
|
@ -7,8 +7,9 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"codeberg.org/danjones000/my-log/tools"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
|
|
@ -73,33 +74,11 @@ func (m *Meta) processMeta(in []byte) error {
|
|||
if len(in) == 0 {
|
||||
return newParsingError(errors.New("No value found"))
|
||||
}
|
||||
s := strings.TrimSpace(string(in))
|
||||
if len(s) == 0 {
|
||||
v := tools.ParseBytes(in)
|
||||
if v == "" {
|
||||
return newParsingError(errors.New("No value found"))
|
||||
}
|
||||
yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$")
|
||||
yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
|
||||
null := regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$")
|
||||
var j json.RawMessage
|
||||
if null.MatchString(s) {
|
||||
m.Value = nil
|
||||
} else if yesno.MatchString(s) {
|
||||
if yes.MatchString(s) {
|
||||
m.Value = true
|
||||
} else {
|
||||
m.Value = false
|
||||
}
|
||||
} else if i, err := strconv.Atoi(s); err == nil {
|
||||
m.Value = i
|
||||
} else if f, err := strconv.ParseFloat(s, 64); err == nil {
|
||||
m.Value = f
|
||||
} else if t, err := time.Parse(time.RFC3339, s); err == nil {
|
||||
m.Value = t
|
||||
} else if err := json.Unmarshal(in, &j); err == nil {
|
||||
m.Value = j
|
||||
} else {
|
||||
m.Value = s
|
||||
}
|
||||
|
||||
m.Value = v
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue