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

Code before:

If a config file is specified, it will be applied immediately after the process
is running. If the config file is not in Caddy's native JSON format, you can
specify an adapter with --adapter to adapt the given config file to
Caddy's native format. The config adapter must be a registered module. Any
warnings will be printed to the log, but beware that any adaptation without
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 (check every 1 second). ⚠️ 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().StringP("envfile", "", "", "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, check every 1s for a change")
			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.

Review comment (suggestion):
```suggestion
changes. ⚠️ This can make unintentional config changes easier; only use this
```

Code after:

If a config file is specified, it will be applied immediately after the process
is running. If the config file is not in Caddy's native JSON format, you can
specify an adapter with --adapter to adapt the given config file to
Caddy's native format. The config adapter must be a registered module. Any
warnings will be printed to the log, but beware that any adaptation without
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().StringP("envfile", "", "", "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.