From 6e2fabb2a46812dee42842c13439e1a0238aa40b Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 22 Mar 2020 22:58:24 -0600 Subject: cmd: Add --watch flag to start & run commands (closes #1806) Because, just for fun. --- cmd/commands.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cmd/commands.go') diff --git a/cmd/commands.go b/cmd/commands.go index d4edc66..43aba01 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -74,7 +74,7 @@ func init() { RegisterCommand(Command{ Name: "start", Func: cmdStart, - Usage: "[--config [[--adapter ]]", + Usage: "[--config [--adapter ]] [--watch]", Short: "Starts the Caddy process in the background and then returns", Long: ` Starts the Caddy process, optionally bootstrapped with an initial config file. @@ -87,6 +87,7 @@ using 'caddy run' instead to keep it in the foreground.`, fs := flag.NewFlagSet("start", flag.ExitOnError) fs.String("config", "", "Configuration file") fs.String("adapter", "", "Name of config adapter to apply") + fs.Bool("watch", false, "Reload changed config file automatically") return fs }(), }) @@ -94,7 +95,7 @@ using 'caddy run' instead to keep it in the foreground.`, RegisterCommand(Command{ Name: "run", Func: cmdRun, - Usage: "[--config [--adapter ]] [--environ]", + Usage: "[--config [--adapter ]] [--environ] [--watch]", Short: `Starts the Caddy process and blocks indefinitely`, Long: ` Starts the Caddy process, optionally bootstrapped with an initial config file, @@ -119,13 +120,18 @@ be printed before starting. This is the same as the environ command but does not quit after printing, and can be useful for troubleshooting. The --resume flag will override the --config flag if there is a config auto- -save file. It is not an error if --resume is used and no autosave file exists.`, +save file. It is not an error if --resume is used and no autosave file exists. + +If --watch is specified, the config file will be loaded automatically after +changes. ⚠️ This is dangerous in production! Only use this option in a local +development environment.`, Flags: func() *flag.FlagSet { fs := flag.NewFlagSet("run", flag.ExitOnError) fs.String("config", "", "Configuration file") fs.String("adapter", "", "Name of config adapter to apply") - fs.Bool("resume", false, "Use saved config, if any (and prefer over --config file)") fs.Bool("environ", false, "Print environment") + fs.Bool("resume", false, "Use saved config, if any (and prefer over --config file)") + fs.Bool("watch", false, "Watch config file for changes and reload it automatically") fs.String("pingback", "", "Echo confirmation bytes to this address on success") return fs }(), -- cgit v1.2.3