emissary/internal/command/common/load_config.go

28 lines
511 B
Go
Raw Permalink Normal View History

2023-02-02 10:55:24 +01:00
package common
import (
"forge.cadoles.com/Cadoles/emissary/internal/config"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func LoadConfig(ctx *cli.Context) (*config.Config, error) {
configFile := ctx.String("config")
var (
conf *config.Config
err error
)
if configFile != "" {
conf, err = config.NewFromFile(configFile)
if err != nil {
return nil, errors.Wrapf(err, "Could not load config file '%s'", configFile)
}
} else {
conf = config.NewDefault()
}
return conf, nil
}