Repository: caddyserver/caddy
File: cmd/commands.go (Go)

Code before:
errors will immediately be used. If you want to review the results of the
adaptation first, use the 'adapt' subcommand.

As a special case, if the current working directory has a file called
"Caddyfile" and the caddyfile config adapter is plugged in (default), then
that file will be loaded and used to configure Caddy, even without any command
line flags.

If --envfile is specified, an environment file with environment variables in
the KEY=VALUE format will be loaded into the Caddy process.

If --environ is specified, the environment as seen by the Caddy process will
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.

If --watch is specified, the config file will be loaded automatically after
changes. ⚠️ This can make unintentional config changes easier; only use this
option in a local development environment.
`,
		CobraFunc: func(cmd *cobra.Command) {
			cmd.Flags().StringP("config", "c", "", "Configuration file")
			cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply")
			cmd.Flags().StringSliceP("envfile", "", []string{}, "Environment file to load")
			cmd.Flags().BoolP("environ", "e", false, "Print environment")
			cmd.Flags().BoolP("resume", "r", false, "Use saved config, if any (and prefer over --config file)")
			cmd.Flags().BoolP("watch", "w", false, "Watch config file for changes and reload it automatically")
			cmd.Flags().StringP("pidfile", "", "", "Path of file to which to write process ID")
			cmd.Flags().StringP("pingback", "", "", "Echo confirmation bytes to this address on success")
			cmd.RunE = WrapCommandFuncForCobra(cmdRun)
		},
	})

	RegisterCommand(Command{
		Name:  "stop",
		Usage: "[--config <path> [--adapter <name>]] [--address <interface>]",
		Short: "Gracefully stops a started Caddy process",
		Long: `
Stops the background Caddy process as gracefully as possible.

It requires that the admin API is enabled and accessible, since it will
use the API's /stop endpoint. The address of this request can be customized
using the --address flag, or from the given --config, if not the default.
`,
		CobraFunc: func(cmd *cobra.Command) {
			cmd.Flags().StringP("config", "c", "", "Configuration file to use to parse the admin address, if --address is not used")
			cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply (when --config is used)")
			cmd.Flags().StringP("address", "", "", "The address to use to reach the admin API endpoint, if not the default")
			cmd.RunE = WrapCommandFuncForCobra(cmdStop)

Review comment (suggestion):
```suggestion
			cmd.Flags().StringSliceP("envfile", "", []string{}, "Environment file(s) to load")
```

Code after:
errors will immediately be used. If you want to review the results of the
adaptation first, use the 'adapt' subcommand.

As a special case, if the current working directory has a file called
"Caddyfile" and the caddyfile config adapter is plugged in (default), then
that file will be loaded and used to configure Caddy, even without any command
line flags.

If --envfile is specified, an environment file with environment variables in
the KEY=VALUE format will be loaded into the Caddy process.

If --environ is specified, the environment as seen by the Caddy process will
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.

If --watch is specified, the config file will be loaded automatically after
changes. ⚠️ This can make unintentional config changes easier; only use this
option in a local development environment.
`,
		CobraFunc: func(cmd *cobra.Command) {
			cmd.Flags().StringP("config", "c", "", "Configuration file")
			cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply")
			cmd.Flags().StringSliceP("envfile", "", []string{}, "Environment file(s) to load")
			cmd.Flags().BoolP("environ", "e", false, "Print environment")
			cmd.Flags().BoolP("resume", "r", false, "Use saved config, if any (and prefer over --config file)")
			cmd.Flags().BoolP("watch", "w", false, "Watch config file for changes and reload it automatically")
			cmd.Flags().StringP("pidfile", "", "", "Path of file to which to write process ID")
			cmd.Flags().StringP("pingback", "", "", "Echo confirmation bytes to this address on success")
			cmd.RunE = WrapCommandFuncForCobra(cmdRun)
		},
	})

	RegisterCommand(Command{
		Name:  "stop",
		Usage: "[--config <path> [--adapter <name>]] [--address <interface>]",
		Short: "Gracefully stops a started Caddy process",
		Long: `
Stops the background Caddy process as gracefully as possible.

It requires that the admin API is enabled and accessible, since it will
use the API's /stop endpoint. The address of this request can be customized
using the --address flag, or from the given --config, if not the default.
`,
		CobraFunc: func(cmd *cobra.Command) {
			cmd.Flags().StringP("config", "c", "", "Configuration file to use to parse the admin address, if --address is not used")
			cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply (when --config is used)")
			cmd.Flags().StringP("address", "", "", "The address to use to reach the admin API endpoint, if not the default")
			cmd.RunE = WrapCommandFuncForCobra(cmdStop)