@marcel91200 / caddy Mirror · read-only / commits / 3592e593
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

cmd: adapt: Make --config flag optional when Caddyfile exists

Matthew Holt committed Feb 4, 2020 at 10:48 UTC 3592e593990d8ae1ca6aec0f5a6d5a0cfa83cf4c
1 file changed +20 -2
cmd/commandfuncs.go
+20 -2
@@ -413,9 +413,27 @@ func cmdAdaptConfig(fl Flags) (int, error) {
413 adaptCmdPrettyFlag := fl.Bool("pretty")
414 adaptCmdValidateFlag := fl.Bool("validate")
415
416 - if adaptCmdAdapterFlag == "" || adaptCmdInputFlag == "" {
416 + // if no input file was specified, try a default
417 + // Caddyfile if the Caddyfile adapter is plugged in
418 + if adaptCmdInputFlag == "" && caddyconfig.GetAdapter("caddyfile") != nil {
419 + _, err := os.Stat("Caddyfile")
420 + if err == nil {
421 + // default Caddyfile exists
422 + adaptCmdInputFlag = "Caddyfile"
423 + caddy.Log().Info("using adjacent Caddyfile")
424 + } else if !os.IsNotExist(err) {
425 + // default Caddyfile exists, but error accessing it
426 + return caddy.ExitCodeFailedStartup, fmt.Errorf("accessing default Caddyfile: %v", err)
427 + }
428 + }
429 +
430 + if adaptCmdInputFlag == "" {
431 + return caddy.ExitCodeFailedStartup,
432 + fmt.Errorf("input file required when there is no Caddyfile in current directory (use --config flag)")
433 + }
434 + if adaptCmdAdapterFlag == "" {
435 return caddy.ExitCodeFailedStartup,
418 - fmt.Errorf("--adapter and --config flags are required")
436 + fmt.Errorf("adapter name is required (use --adapt flag or leave unspecified for default)")
437 }
438
439 cfgAdapter := caddyconfig.GetAdapter(adaptCmdAdapterFlag)