From ed10863494dfc9985d95b8df660b7ae66006fc5b Mon Sep 17 00:00:00 2001 From: Benoit Benedetti Date: Tue, 8 Sep 2015 20:14:23 +0200 Subject: [PATCH 1/2] Configuration as command line arg #222 --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 947548a5..3342ae7c 100644 --- a/main.go +++ b/main.go @@ -124,7 +124,7 @@ func isLocalhost(s string) bool { // loadConfigs loads configuration from a file or stdin (piped). // The configurations are grouped by bind address. // Configuration is obtained from one of three sources, tried -// in this order: 1. -conf flag, 2. stdin, 3. Caddyfile. +// in this order: 1. -conf flag, 2. stdin, 4. command line argument 3. Caddyfile. // If none of those are available, a default configuration is // loaded. func loadConfigs() (config.Group, error) { @@ -155,6 +155,12 @@ func loadConfigs() (config.Group, error) { } } + // Command line Arg + if flag.NArg() > 0 { + confBody := ":" + config.DefaultPort + "\n" + strings.Join(flag.Args(), "\n") + return config.Load("args", bytes.NewBufferString(confBody)) + } + // Caddyfile file, err := os.Open(config.DefaultConfigFile) if err != nil { From 5d32af8a6b8e48fa97de93eeac84cedc3b68bd7f Mon Sep 17 00:00:00 2001 From: Benoit Benedetti Date: Tue, 8 Sep 2015 22:38:30 +0200 Subject: [PATCH 2/2] Fix typo in loadConfigs comment --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3342ae7c..c1c0d143 100644 --- a/main.go +++ b/main.go @@ -124,7 +124,7 @@ func isLocalhost(s string) bool { // loadConfigs loads configuration from a file or stdin (piped). // The configurations are grouped by bind address. // Configuration is obtained from one of three sources, tried -// in this order: 1. -conf flag, 2. stdin, 4. command line argument 3. Caddyfile. +// in this order: 1. -conf flag, 2. stdin, 3. command line argument 4. Caddyfile. // If none of those are available, a default configuration is // loaded. func loadConfigs() (config.Group, error) {