Browse Source
cmd: Make --config flag optional for reload command
In case it is using the default Caddyfile
master
Matthew Holt
5 years ago
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with
2 additions and
8 deletions
-
cmd/commandfuncs.go
-
cmd/main.go
|
|
@ -264,12 +264,6 @@ func cmdReload(fl Flags) (int, error) { |
|
|
|
reloadCmdConfigAdapterFlag := fl.String("adapter") |
|
|
|
reloadCmdAddrFlag := fl.String("address") |
|
|
|
|
|
|
|
// a configuration is required
|
|
|
|
if reloadCmdConfigFlag == "" { |
|
|
|
return caddy.ExitCodeFailedStartup, |
|
|
|
fmt.Errorf("no configuration to load (use --config)") |
|
|
|
} |
|
|
|
|
|
|
|
// get the config in caddy's native format
|
|
|
|
config, err := loadConfig(reloadCmdConfigFlag, reloadCmdConfigAdapterFlag) |
|
|
|
if err != nil { |
|
|
@ -278,7 +272,7 @@ func cmdReload(fl Flags) (int, error) { |
|
|
|
|
|
|
|
// get the address of the admin listener and craft endpoint URL
|
|
|
|
adminAddr := reloadCmdAddrFlag |
|
|
|
if adminAddr == "" { |
|
|
|
if adminAddr == "" && len(config) > 0 { |
|
|
|
var tmpStruct struct { |
|
|
|
Admin caddy.AdminConfig `json:"admin"` |
|
|
|
} |
|
|
|
|
|
@ -97,7 +97,7 @@ func handlePingbackConn(conn net.Conn, expect []byte) error { |
|
|
|
// the resulting JSON config bytes.
|
|
|
|
func loadConfig(configFile, adapterName string) ([]byte, error) { |
|
|
|
// specifying an adapter without a config file is ambiguous
|
|
|
|
if configFile == "" && adapterName != "" { |
|
|
|
if adapterName != "" && configFile == "" { |
|
|
|
return nil, fmt.Errorf("cannot adapt config without config file (use --config)") |
|
|
|
} |
|
|
|
|
|
|
|