@@ -17,7 +17,6 @@ import (
17
17
"errors"
18
18
"fmt"
19
19
"io"
20
- "io/ioutil"
21
20
"os"
22
21
"os/exec"
23
22
"regexp"
@@ -44,7 +43,7 @@ func Parse(r io.Reader) (map[string]string, error) {
44
43
45
44
// ParseWithLookup reads an env file from io.Reader, returning a map of keys and values.
46
45
func ParseWithLookup (r io.Reader , lookupFn LookupFn ) (map [string ]string , error ) {
47
- data , err := ioutil .ReadAll (r )
46
+ data , err := io .ReadAll (r )
48
47
if err != nil {
49
48
return nil , err
50
49
}
@@ -184,7 +183,7 @@ func Marshal(envMap map[string]string) (string, error) {
184
183
if d , err := strconv .Atoi (v ); err == nil {
185
184
lines = append (lines , fmt .Sprintf (`%s=%d` , k , d ))
186
185
} else {
187
- lines = append (lines , fmt .Sprintf (`%s="%s"` , k , doubleQuoteEscape (v )))
186
+ lines = append (lines , fmt .Sprintf (`%s="%s"` , k , doubleQuoteEscape (v ))) //nolint // Cannot use %q here
188
187
}
189
188
}
190
189
sort .Strings (lines )
@@ -235,10 +234,9 @@ var exportRegex = regexp.MustCompile(`^\s*(?:export\s+)?(.*?)\s*$`)
235
234
func parseLine (line string , envMap map [string ]string ) (key string , value string , err error ) {
236
235
return parseLineWithLookup (line , envMap , nil )
237
236
}
238
- func parseLineWithLookup (line string , envMap map [string ]string , lookupFn LookupFn ) (key string , value string , err error ) {
239
- if len (line ) == 0 {
240
- err = errors .New ("zero length string" )
241
- return
237
+ func parseLineWithLookup (line string , envMap map [string ]string , lookupFn LookupFn ) (string , string , error ) {
238
+ if line == "" {
239
+ return "" , "" , errors .New ("zero length string" )
242
240
}
243
241
244
242
// ditch the comments (but keep quoted hashes)
@@ -271,14 +269,14 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF
271
269
}
272
270
273
271
if len (splitString ) != 2 {
274
- err = errors .New ("can't separate key from value" )
275
- return
272
+ return "" , "" , errors .New ("can't separate key from value" )
276
273
}
277
- key = exportRegex .ReplaceAllString (splitString [0 ], "$1" )
274
+ key : = exportRegex .ReplaceAllString (splitString [0 ], "$1" )
278
275
279
276
// Parse the value
280
- value = parseValue (splitString [1 ], envMap , lookupFn )
281
- return
277
+ value := parseValue (splitString [1 ], envMap , lookupFn )
278
+
279
+ return key , value , nil
282
280
}
283
281
284
282
var (
@@ -351,7 +349,7 @@ func doubleQuoteEscape(line string) string {
351
349
if c == '\r' {
352
350
toReplace = `\r`
353
351
}
354
- line = strings .Replace (line , string (c ), toReplace , - 1 )
352
+ line = strings .ReplaceAll (line , string (c ), toReplace )
355
353
}
356
354
return line
357
355
}
0 commit comments