From 3b6c387b8401f35b30506c3eca2821ad61c3f71d Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 13 Mar 2016 12:59:35 +0100 Subject: [PATCH 1/2] Add flag to list directives. --- main.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index b509b12fd..dca6a87ba 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "github.com/mholt/caddy/caddy" "github.com/mholt/caddy/caddy/https" + "github.com/mholt/caddy/caddy/parse" "github.com/xenolf/lego/acme" "gopkg.in/natefinch/lumberjack.v2" ) @@ -36,6 +37,7 @@ func init() { flag.StringVar(&revoke, "revoke", "", "Hostname for which to revoke the certificate") flag.StringVar(&caddy.Root, "root", caddy.DefaultRoot, "Root path to default site") flag.BoolVar(&version, "version", false, "Show version") + flag.BoolVar(&directives, "directives", false, "List supported directives") } func main() { @@ -77,6 +79,12 @@ func main() { } os.Exit(0) } + if directives { + for d := range parse.ValidDirectives { + fmt.Println(d) + } + os.Exit(0) + } // Set CPU cap err := setCPU(cpu) @@ -212,11 +220,12 @@ const appName = "Caddy" // Flags that control program flow or startup var ( - conf string - cpu string - logfile string - revoke string - version bool + conf string + cpu string + logfile string + revoke string + version bool + directives bool ) // Build information obtained with the help of -ldflags From 44fc9b18a61aeffdb970aede0b52795de17f6893 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 13 Mar 2016 18:29:26 +0100 Subject: [PATCH 2/2] Print the directives in order of priority. --- caddy/directives.go | 9 +++++++++ main.go | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/caddy/directives.go b/caddy/directives.go index 87f6233d8..fd5245085 100644 --- a/caddy/directives.go +++ b/caddy/directives.go @@ -69,6 +69,15 @@ var directiveOrder = []directive{ {"browse", setup.Browse}, } +// Directives returns the list of directives in order of priority. +func Directives() []string { + directives := make([]string, len(directiveOrder)) + for i, d := range directiveOrder { + directives[i] = d.name + } + return directives +} + // RegisterDirective adds the given directive to caddy's list of directives. // Pass the name of a directive you want it to be placed after, // otherwise it will be placed at the bottom of the stack. diff --git a/main.go b/main.go index dca6a87ba..abb1b3f39 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,6 @@ import ( "github.com/mholt/caddy/caddy" "github.com/mholt/caddy/caddy/https" - "github.com/mholt/caddy/caddy/parse" "github.com/xenolf/lego/acme" "gopkg.in/natefinch/lumberjack.v2" ) @@ -80,7 +79,7 @@ func main() { os.Exit(0) } if directives { - for d := range parse.ValidDirectives { + for _, d := range caddy.Directives() { fmt.Println(d) } os.Exit(0)