2020-04-28 02:42:44 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-09-11 20:32:23 +02:00
|
|
|
"errors"
|
|
|
|
"io/fs"
|
2020-04-28 02:42:44 +02:00
|
|
|
"os"
|
|
|
|
|
2022-06-22 02:11:15 +02:00
|
|
|
"github.com/caarlos0/log"
|
2023-07-25 13:26:44 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/logext"
|
2020-04-28 02:42:44 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func loadConfig(path string) (config.Project, error) {
|
2023-07-11 20:25:33 +02:00
|
|
|
p, _, err := loadConfigCheck(path)
|
|
|
|
return p, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfigCheck(path string) (config.Project, string, error) {
|
2022-06-23 03:03:00 +02:00
|
|
|
if path == "-" {
|
|
|
|
log.Info("loading config from stdin")
|
2023-07-11 20:25:33 +02:00
|
|
|
p, err := config.LoadReader(os.Stdin)
|
|
|
|
return p, path, err
|
2022-06-23 03:03:00 +02:00
|
|
|
}
|
2020-04-28 02:42:44 +02:00
|
|
|
if path != "" {
|
2023-07-11 20:25:33 +02:00
|
|
|
p, err := config.Load(path)
|
|
|
|
return p, path, err
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
for _, f := range [4]string{
|
|
|
|
".goreleaser.yml",
|
|
|
|
".goreleaser.yaml",
|
|
|
|
"goreleaser.yml",
|
|
|
|
"goreleaser.yaml",
|
|
|
|
} {
|
|
|
|
proj, err := config.Load(f)
|
2022-09-11 20:32:23 +02:00
|
|
|
if err != nil && errors.Is(err, fs.ErrNotExist) {
|
2020-04-28 02:42:44 +02:00
|
|
|
continue
|
|
|
|
}
|
2023-07-11 20:25:33 +02:00
|
|
|
return proj, f, err
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|
|
|
|
// the user didn't specify a config file and the known possible file names
|
|
|
|
// don't exist, so, return an empty config and a nil err.
|
2023-07-25 13:26:44 +02:00
|
|
|
log.Warn(logext.Warning("could not find a configuration file, using defaults..."))
|
2023-07-11 20:25:33 +02:00
|
|
|
return config.Project{}, "", nil
|
2020-04-28 02:42:44 +02:00
|
|
|
}
|