Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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>
Jesse committed
May 3, 2021 at 02:38 UTC
e6f6d3a4765565b09f95a29a2e75be34e1d70359
2 files changed
+9
-1
cmd/commandfuncs.go
+4
@@ -45,6 +45,7 @@ func cmdStart(fl Flags) (int, error) {
45
startCmdConfigAdapterFlag := fl.String("adapter")
46
startCmdPidfileFlag := fl.String("pidfile")
47
startCmdWatchFlag := fl.Bool("watch")
48
+ startCmdEnvfileFlag := fl.String("envfile")
49
50
// open a listener to which the child process will connect when
51
// it is ready to confirm that it has successfully started
@@ -68,6 +69,9 @@ func cmdStart(fl Flags) (int, error) {
69
if startCmdConfigFlag != "" {
70
cmd.Args = append(cmd.Args, "--config", startCmdConfigFlag)
71
}
72
+ if startCmdEnvfileFlag != "" {
73
+ cmd.Args = append(cmd.Args, "--envfile", startCmdEnvfileFlag)
74
+ }
75
if startCmdConfigAdapterFlag != "" {
76
cmd.Args = append(cmd.Args, "--adapter", startCmdConfigAdapterFlag)
77
}
cmd/commands.go
+5
-1
@@ -74,18 +74,22 @@ func init() {
74
RegisterCommand(Command{
75
Name: "start",
76
Func: cmdStart,
77
- Usage: "[--config <path> [--adapter <name>]] [--watch] [--pidfile <file>]",
77
+ Usage: "[--config <path> [--adapter <name>]] [--envfile <path>] [--watch] [--pidfile <file>]",
78
Short: "Starts the Caddy process in the background and then returns",
79
Long: `
80
Starts the Caddy process, optionally bootstrapped with an initial config file.
81
This command unblocks after the server starts running or fails to run.
82
83
+If --envfile is specified, an environment file with environment variables in
84
+the KEY=VALUE format will be loaded into the Caddy process.
85
+
86
On Windows, the spawned child process will remain attached to the terminal, so
87
closing the window will forcefully stop Caddy; to avoid forgetting this, try
88
using 'caddy run' instead to keep it in the foreground.`,
89
Flags: func() *flag.FlagSet {
90
fs := flag.NewFlagSet("start", flag.ExitOnError)
91
fs.String("config", "", "Configuration file")
92
+ fs.String("envfile", "", "Environment file to load")
93
fs.String("adapter", "", "Name of config adapter to apply")
94
fs.String("pidfile", "", "Path of file to which to write process ID")
95
fs.Bool("watch", false, "Reload changed config file automatically")