2020-03-09 16:00:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
2020-10-30 15:20:57 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2020-03-09 16:00:04 +00:00
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
"github.com/moby/buildkit/cmd/buildkitd/config"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Load(r io.Reader) (config.Config, *toml.MetaData, error) {
|
|
|
|
var c config.Config
|
|
|
|
md, err := toml.DecodeReader(r, &c)
|
|
|
|
if err != nil {
|
|
|
|
return c, nil, errors.Wrap(err, "failed to parse config")
|
|
|
|
}
|
|
|
|
return c, &md, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoadFile(fp string) (config.Config, *toml.MetaData, error) {
|
|
|
|
f, err := os.Open(fp)
|
|
|
|
if err != nil {
|
2020-04-19 05:17:47 +00:00
|
|
|
if errors.Is(err, os.ErrNotExist) {
|
2020-03-09 16:00:04 +00:00
|
|
|
return config.Config{}, nil, nil
|
|
|
|
}
|
|
|
|
return config.Config{}, nil, errors.Wrapf(err, "failed to load config from %s", fp)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
return Load(f)
|
|
|
|
}
|
2020-10-30 15:20:57 +00:00
|
|
|
|
|
|
|
// parseBoolOrAuto returns (nil, nil) if s is "auto"
|
|
|
|
func parseBoolOrAuto(s string) (*bool, error) {
|
|
|
|
if s == "" || strings.ToLower(s) == "auto" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
b, err := strconv.ParseBool(s)
|
|
|
|
return &b, err
|
|
|
|
}
|