diff options
author | Jesse <szx961102@gmail.com> | 2021-05-03 02:38:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-02 12:38:16 -0600 |
commit | e6f6d3a4765565b09f95a29a2e75be34e1d70359 (patch) | |
tree | 4c262608e8f626abda574db9b59e9fefc6c56c05 | |
parent | ef7f15f3a42474319e2db0dff6720d91c153f0bf (diff) |
cmd: Add --envfile flag to `start` command (#4141)
* add envfile in start cmd
* fix commandfuncs
* fix commandfuncs
* fix cmdStart envfile from bool to string
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
-rw-r--r-- | cmd/commandfuncs.go | 4 | ||||
-rw-r--r-- | cmd/commands.go | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index d32b9c7..f24a9d0 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -45,6 +45,7 @@ func cmdStart(fl Flags) (int, error) { startCmdConfigAdapterFlag := fl.String("adapter") startCmdPidfileFlag := fl.String("pidfile") startCmdWatchFlag := fl.Bool("watch") + startCmdEnvfileFlag := fl.String("envfile") // open a listener to which the child process will connect when // it is ready to confirm that it has successfully started @@ -68,6 +69,9 @@ func cmdStart(fl Flags) (int, error) { if startCmdConfigFlag != "" { cmd.Args = append(cmd.Args, "--config", startCmdConfigFlag) } + if startCmdEnvfileFlag != "" { + cmd.Args = append(cmd.Args, "--envfile", startCmdEnvfileFlag) + } if startCmdConfigAdapterFlag != "" { cmd.Args = append(cmd.Args, "--adapter", startCmdConfigAdapterFlag) } diff --git a/cmd/commands.go b/cmd/commands.go index a519896..36e9c04 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -74,18 +74,22 @@ func init() { RegisterCommand(Command{ Name: "start", Func: cmdStart, - Usage: "[--config <path> [--adapter <name>]] [--watch] [--pidfile <file>]", + Usage: "[--config <path> [--adapter <name>]] [--envfile <path>] [--watch] [--pidfile <file>]", Short: "Starts the Caddy process in the background and then returns", Long: ` Starts the Caddy process, optionally bootstrapped with an initial config file. This command unblocks after the server starts running or fails to run. +If --envfile is specified, an environment file with environment variables in +the KEY=VALUE format will be loaded into the Caddy process. + On Windows, the spawned child process will remain attached to the terminal, so closing the window will forcefully stop Caddy; to avoid forgetting this, try using 'caddy run' instead to keep it in the foreground.`, Flags: func() *flag.FlagSet { fs := flag.NewFlagSet("start", flag.ExitOnError) fs.String("config", "", "Configuration file") + fs.String("envfile", "", "Environment file to load") fs.String("adapter", "", "Name of config adapter to apply") fs.String("pidfile", "", "Path of file to which to write process ID") fs.Bool("watch", false, "Reload changed config file automatically") |