support for docker run
environment variables file
Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
parent
74349e02c6
commit
2ca6939ac2
1 changed files with 44 additions and 0 deletions
44
opts/envfile.go
Normal file
44
opts/envfile.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package opts
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
/*
|
||||
Read in a line delimited file with environment variables enumerated
|
||||
*/
|
||||
func ParseEnvFile(filename string) ([]string, error) {
|
||||
fh, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
var (
|
||||
lines []string = []string{}
|
||||
line, chunk []byte
|
||||
)
|
||||
reader := bufio.NewReader(fh)
|
||||
line, isPrefix, err := reader.ReadLine()
|
||||
|
||||
for err == nil {
|
||||
if isPrefix {
|
||||
chunk = append(chunk, line...)
|
||||
} else if !isPrefix && len(chunk) > 0 {
|
||||
line = chunk
|
||||
chunk = []byte{}
|
||||
} else {
|
||||
chunk = []byte{}
|
||||
}
|
||||
|
||||
if !isPrefix && len(line) > 0 && bytes.Contains(line, []byte("=")) {
|
||||
lines = append(lines, string(line))
|
||||
}
|
||||
line, isPrefix, err = reader.ReadLine()
|
||||
}
|
||||
if err != nil && err != io.EOF {
|
||||
return []string{}, err
|
||||
}
|
||||
return lines, nil
|
||||
}
|
Loading…
Reference in a new issue