diff options
author | Omar Hussein <[email protected]> | 2024-04-11 17:28:16 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-11 15:28:16 -0600 |
commit | 185ed6fe7c14a88512d7cdcc308477a4f58cca4b (patch) | |
tree | 54e2bc4ea990c83e3c3fde112d0e3f7f1f49b695 /cmd | |
parent | 4a0492f3e178c8ab970234b27702c76fedffec5f (diff) | |
download | caddy-185ed6fe7c14a88512d7cdcc308477a4f58cca4b.tar.gz caddy-185ed6fe7c14a88512d7cdcc308477a4f58cca4b.zip |
cmd: Assume Caddyfile based on filename prefix and suffix (#5919)
This can be helpful if editors only consider file extensions for certain features.
* added special case support for caddyfile suffix, case insensitive
* Update cmd/main.go
Co-authored-by: Matt Holt <[email protected]>
* skip caddyfile adapter for registered file extensions
---------
Co-authored-by: Matt Holt <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/main.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cmd/main.go b/cmd/main.go index d832cbc5e..9be3585b9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -157,11 +157,16 @@ func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([ } } - // as a special case, if a config file called "Caddyfile" was - // specified, and no adapter is specified, assume caddyfile adapter - // for convenience - if strings.HasPrefix(filepath.Base(configFile), "Caddyfile") && - filepath.Ext(configFile) != ".json" && + // as a special case, if a config file starts with "caddyfile" or + // has a ".caddyfile" extension, and no adapter is specified, and + // no adapter module name matches the extension, assume + // caddyfile adapter for convenience + baseConfig := strings.ToLower(filepath.Base(configFile)) + baseConfigExt := filepath.Ext(baseConfig) + if (strings.HasPrefix(baseConfig, "caddyfile") || + strings.HasSuffix(baseConfig, ".caddyfile")) && + caddyconfig.GetAdapter(baseConfigExt[1:]) == nil && + baseConfigExt != ".json" && adapterName == "" { adapterName = "caddyfile" } |