mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 13:43:47 +03:00
cmd: Use loadConfig() for validate as run, start, and reload do
This commit is contained in:
parent
36a6c7daf0
commit
99d34f1c1d
1 changed files with 2 additions and 27 deletions
|
@ -492,35 +492,10 @@ func cmdValidateConfig(fl Flags) (int, error) {
|
|||
validateCmdConfigFlag := fl.String("config")
|
||||
validateCmdAdapterFlag := fl.String("adapter")
|
||||
|
||||
input, err := ioutil.ReadFile(validateCmdConfigFlag)
|
||||
input, _, err := loadConfig(validateCmdConfigFlag, validateCmdAdapterFlag)
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup,
|
||||
fmt.Errorf("reading input file: %v", err)
|
||||
return caddy.ExitCodeFailedStartup, err
|
||||
}
|
||||
|
||||
if validateCmdAdapterFlag != "" {
|
||||
cfgAdapter := caddyconfig.GetAdapter(validateCmdAdapterFlag)
|
||||
if cfgAdapter == nil {
|
||||
return caddy.ExitCodeFailedStartup,
|
||||
fmt.Errorf("unrecognized config adapter: %s", validateCmdAdapterFlag)
|
||||
}
|
||||
|
||||
adaptedConfig, warnings, err := cfgAdapter.Adapt(input, nil)
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, err
|
||||
}
|
||||
// print warnings to stderr
|
||||
for _, warn := range warnings {
|
||||
msg := warn.Message
|
||||
if warn.Directive != "" {
|
||||
msg = fmt.Sprintf("%s: %s", warn.Directive, warn.Message)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "[WARNING][%s] %s:%d: %s\n", validateCmdAdapterFlag, warn.File, warn.Line, msg)
|
||||
}
|
||||
|
||||
input = adaptedConfig
|
||||
}
|
||||
|
||||
input = caddy.RemoveMetaFields(input)
|
||||
|
||||
var cfg *caddy.Config
|
||||
|
|
Loading…
Reference in a new issue