bump compose-go to v2.4.9

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours
2025-03-14 14:40:03 +01:00
committed by CrazyMax
parent 00fdcd38ab
commit bf95aa3dfa
33 changed files with 637 additions and 164 deletions

View File

@ -21,7 +21,17 @@ import (
"io"
)
var formats = map[string]Parser{}
const DotEnv = ".env"
var formats = map[string]Parser{
DotEnv: func(r io.Reader, filename string, lookup func(key string) (string, bool)) (map[string]string, error) {
m, err := ParseWithLookup(r, lookup)
if err != nil {
return nil, fmt.Errorf("failed to read %s: %w", filename, err)
}
return m, nil
},
}
type Parser func(r io.Reader, filename string, lookup func(key string) (string, bool)) (map[string]string, error)
@ -30,9 +40,12 @@ func RegisterFormat(format string, p Parser) {
}
func ParseWithFormat(r io.Reader, filename string, resolve LookupFn, format string) (map[string]string, error) {
parser, ok := formats[format]
if format == "" {
format = DotEnv
}
fn, ok := formats[format]
if !ok {
return nil, fmt.Errorf("unsupported env_file format %q", format)
}
return parser(r, filename, resolve)
return fn(r, filename, resolve)
}

View File

@ -30,7 +30,7 @@ var startsWithDigitRegex = regexp.MustCompile(`^\s*\d.*`) // Keys starting with
// LookupFn represents a lookup function to resolve variables from
type LookupFn func(string) (string, bool)
var noLookupFn = func(s string) (string, bool) {
var noLookupFn = func(_ string) (string, bool) {
return "", false
}

View File

@ -115,7 +115,7 @@ loop:
switch rune {
case '=', ':', '\n':
// library also supports yaml-style value declaration
key = string(src[0:i])
key = src[0:i]
offset = i + 1
inherited = rune == '\n'
break loop
@ -157,7 +157,7 @@ func (p *parser) extractVarValue(src string, envMap map[string]string, lookupFn
// Remove inline comments on unquoted lines
value, _, _ = strings.Cut(value, " #")
value = strings.TrimRightFunc(value, unicode.IsSpace)
retVal, err := expandVariables(string(value), envMap, lookupFn)
retVal, err := expandVariables(value, envMap, lookupFn)
return retVal, rest, err
}