@@ -19,29 +19,40 @@ import (
19
19
"regexp"
20
20
)
21
21
22
- // Command represents a subcommand. All fields
23
- // are required to be set except for Flags if
24
- // there are no flags and Usage if there are
25
- // no flags or arguments.
22
+ // Command represents a subcommand. Name, Func,
23
+ // and Short are required.
26
24
type Command struct {
25
+ // The name of the subcommand. Must conform to the
26
+ // format described by the RegisterCommand() godoc.
27
+ // Required.
27
28
Name string
28
29
29
- // Run is a function that executes a subcommand.
30
- // It returns an exit code and any associated error.
31
- // Takes non-flag commandline arguments as args .
32
- // Flag must be parsed before Run is executed .
30
+ // Run is a function that executes a subcommand using
31
+ // the parsed flags. It returns an exit code and any
32
+ // associated error .
33
+ // Required .
33
34
Func CommandFunc
34
35
35
- // Usage is the one-line message explaining args, flags.
36
+ // Usage is a brief message describing the syntax of
37
+ // the subcommand's flags and args. Use [] to indicate
38
+ // optional parameters and <> to enclose literal values
39
+ // intended to be replaced by the user. Do not prefix
40
+ // the string with "caddy" or the name of the command
41
+ // since these will be prepended for you; only include
42
+ // the actual parameters for this command.
36
43
Usage string
37
44
38
- // Short is the short description for command.
45
+ // Short is a one-line message explaining what the
46
+ // command does. Should not end with punctuation.
47
+ // Required.
39
48
Short string
40
49
41
- // Long is the message for 'caddy help <command>'
50
+ // Long is the full help text shown to the user.
51
+ // Will be trimmed of whitespace on both ends before
52
+ // being printed.
42
53
Long string
43
54
44
- // Flags is flagset for command.
55
+ // Flags is the flagset for command.
45
56
Flags * flag.FlagSet
46
57
}
47
58
@@ -54,14 +65,15 @@ var commands = map[string]Command{
54
65
"start" : {
55
66
Name : "start" ,
56
67
Func : cmdStart ,
57
- Usage : "[--config <path>] [ --adapter <name>]" ,
58
- Short : "Starts the Caddy process and returns after server has started. " ,
68
+ Usage : "[--config <path> [[ --adapter <name>] ]" ,
69
+ Short : "Starts the Caddy process in the background and then returns " ,
59
70
Long : `
60
- Starts the Caddy process, optionally bootstrapped with an initial
61
- config file. Blocks until server is successfully running (or fails to run),
62
- then returns. On Windows, the child process will remain attached to the
63
- terminal, so closing the window will forcefully stop Caddy. See run for more
64
- details.` ,
71
+ Starts the Caddy process, optionally bootstrapped with an initial config file.
72
+ This command unblocks after the server starts running or fails to run.
73
+
74
+ On Windows, the spawned child process will remain attached to the terminal, so
75
+ closing the window will forcefully stop Caddy; to avoid forgetting this, try
76
+ using 'caddy run' instead to keep it in the foreground.` ,
65
77
Flags : func () * flag.FlagSet {
66
78
fs := flag .NewFlagSet ("start" , flag .ExitOnError )
67
79
fs .String ("config" , "" , "Configuration file" )
@@ -73,13 +85,12 @@ details.`,
73
85
"run" : {
74
86
Name : "run" ,
75
87
Func : cmdRun ,
76
- Usage : "[--config <path>] [--adapter <name>] [--print-env ]" ,
77
- Short : `Starts the Caddy process and blocks indefinitely. ` ,
88
+ Usage : "[--config <path> [--adapter <name>]] [--environ ]" ,
89
+ Short : `Starts the Caddy process and blocks indefinitely` ,
78
90
Long : `
79
- Same as start, but blocks indefinitely; i.e. runs Caddy in "daemon" mode. On
80
- Windows, this is recommended over caddy start when running Caddy manually since
81
- it will be more obvious that Caddy is still running and bound to the terminal
82
- window.
91
+ Starts the Caddy process, optionally bootstrapped with an initial config file,
92
+ and blocks indefinitely until the server is stopped; i.e. runs Caddy in
93
+ "daemon" mode (foreground).
83
94
84
95
If a config file is specified, it will be applied immediately after the process
85
96
is running. If the config file is not in Caddy's native JSON format, you can
@@ -90,13 +101,13 @@ errors will immediately be used. If you want to review the results of the
90
101
adaptation first, use the 'adapt' subcommand.
91
102
92
103
As a special case, if the current working directory has a file called
93
- "Caddyfile" and the caddyfile config adapter is plugged in (default), then that
94
- file will be loaded and used to configure Caddy, even without any command line
95
- flags.
104
+ "Caddyfile" and the caddyfile config adapter is plugged in (default), then
105
+ that file will be loaded and used to configure Caddy, even without any command
106
+ line flags.
96
107
97
108
If --environ is specified, the environment as seen by the Caddy process will
98
109
be printed before starting. This is the same as the environ command but does
99
- not quit after printing.` ,
110
+ not quit after printing, and can be useful for troubleshooting .` ,
100
111
Flags : func () * flag.FlagSet {
101
112
fs := flag .NewFlagSet ("run" , flag .ExitOnError )
102
113
fs .String ("config" , "" , "Configuration file" )
@@ -111,26 +122,32 @@ not quit after printing.`,
111
122
Name : "stop" ,
112
123
Func : cmdStop ,
113
124
Short : "Gracefully stops the running Caddy process" ,
114
- Long : `Gracefully stops the running Caddy process. (Note: this will stop any process
115
- named the same as the executable.) On Windows, this stop is forceful and Caddy
116
- will not have an opportunity to clean up any active locks; for a graceful
117
- shutdown on Windows, use Ctrl+C or the /stop endpoint.` ,
125
+ Long : `
126
+ Stops the running Caddy process as gracefully as possible.
127
+
128
+ On Windows, this stop is forceful and Caddy will not have an opportunity to
129
+ clean up any active locks; for a graceful shutdown on Windows, use Ctrl+C
130
+ or the /stop API endpoint.
131
+
132
+ Note: this will stop any process named the same as the executable (os.Args[0]).` ,
118
133
},
119
134
120
135
"reload" : {
121
136
Name : "reload" ,
122
137
Func : cmdReload ,
123
138
Usage : "--config <path> [--adapter <name>] [--address <interface>]" ,
124
- Short : "Gives the running Caddy instance a new configuration" ,
125
- Long : `Gives the running Caddy instance a new configuration. This has the same effect
126
- as POSTing a document to the /load endpoint, but is convenient for simple
127
- workflows revolving around config files. Since the admin endpoint is
128
- configurable, the endpoint configuration is loaded from the --address flag if
129
- specified; otherwise it is loaded from the given config file; otherwise the
130
- default is assumed.` ,
139
+ Short : "Changes the config of the running Caddy instance" ,
140
+ Long : `
141
+ Gives the running Caddy instance a new configuration. This has the same effect
142
+ as POSTing a document to the /load API endpoint, but is convenient for simple
143
+ workflows revolving around config files.
144
+
145
+ Since the admin endpoint is configurable, the endpoint configuration is loaded
146
+ from the --address flag if specified; otherwise it is loaded from the given
147
+ config file; otherwise the default is assumed.` ,
131
148
Flags : func () * flag.FlagSet {
132
149
fs := flag .NewFlagSet ("reload" , flag .ExitOnError )
133
- fs .String ("config" , "" , "Configuration file" )
150
+ fs .String ("config" , "" , "Configuration file (required) " )
134
151
fs .String ("adapter" , "" , "Name of config adapter to apply" )
135
152
fs .String ("address" , "" , "Address of the administration listener, if different from config" )
136
153
return fs
@@ -140,15 +157,14 @@ default is assumed.`,
140
157
"version" : {
141
158
Name : "version" ,
142
159
Func : cmdVersion ,
143
- Short : "Prints the version." ,
144
- Long : `Prints the version.` ,
160
+ Short : "Prints the version" ,
145
161
},
146
162
147
163
"list-modules" : {
148
164
Name : "list-modules" ,
149
165
Func : cmdListModules ,
150
- Short : "List installed Caddy modules. " ,
151
- Long : `List installed Caddy modules.` ,
166
+ Usage : "[--versions] " ,
167
+ Short : "Lists the installed Caddy modules" ,
152
168
Flags : func () * flag.FlagSet {
153
169
fs := flag .NewFlagSet ("list-modules" , flag .ExitOnError )
154
170
fs .Bool ("versions" , false , "Print version information" )
@@ -159,24 +175,30 @@ default is assumed.`,
159
175
"environ" : {
160
176
Name : "environ" ,
161
177
Func : cmdEnviron ,
162
- Short : "Prints the environment as seen by Caddy." ,
163
- Long : `Prints the environment as seen by Caddy.` ,
178
+ Short : "Prints the environment" ,
164
179
},
165
180
166
181
"adapt" : {
167
182
Name : "adapt" ,
168
183
Func : cmdAdaptConfig ,
169
- Usage : "--config <path> --adapter <name> [--pretty]" ,
170
- Short : "Adapts a configuration to Caddy's native JSON config structure " ,
184
+ Usage : "--config <path> --adapter <name> [--pretty] [--validate] " ,
185
+ Short : "Adapts a configuration to Caddy's native JSON" ,
171
186
Long : `
172
- Adapts a configuration to Caddy's native JSON config structure and writes the
173
- output to stdout, along with any warnings to stderr. If --pretty is specified,
174
- the output will be formatted with indentation for human readability.` ,
187
+ Adapts a configuration to Caddy's native JSON format and writes the
188
+ output to stdout, along with any warnings to stderr.
189
+
190
+ If --pretty is specified, the output will be formatted with indentation
191
+ for human readability.
192
+
193
+ If --validate is used, the adapted config will be checked for validity.
194
+ If the config is invalid, an error will be printed to stderr and a non-
195
+ zero exit status will be returned.` ,
175
196
Flags : func () * flag.FlagSet {
176
197
fs := flag .NewFlagSet ("adapt" , flag .ExitOnError )
177
- fs .String ("config" , "" , "Configuration file to adapt" )
178
- fs .String ("adapter" , "" , "Name of config adapter" )
198
+ fs .String ("config" , "" , "Configuration file to adapt (required) " )
199
+ fs .String ("adapter" , "" , "Name of config adapter (required) " )
179
200
fs .Bool ("pretty" , false , "Format the output for human readability" )
201
+ fs .Bool ("validate" , false , "Validate the output" )
180
202
return fs
181
203
}(),
182
204
},
@@ -185,10 +207,11 @@ the output will be formatted with indentation for human readability.`,
185
207
Name : "validate" ,
186
208
Func : cmdValidateConfig ,
187
209
Usage : "--config <path> [--adapter <name>]" ,
188
- Short : "Tests whether a configuration file is valid. " ,
210
+ Short : "Tests whether a configuration file is valid" ,
189
211
Long : `
190
- Loads and provisions the provided config, but does not start
191
- running it.` ,
212
+ Loads and provisions the provided config, but does not start running it.
213
+ This reveals any errors with the configuration through the loading and
214
+ provisioning stages.` ,
192
215
Flags : func () * flag.FlagSet {
193
216
fs := flag .NewFlagSet ("load" , flag .ExitOnError )
194
217
fs .String ("config" , "" , "Input configuration file" )
@@ -208,7 +231,7 @@ func init() {
208
231
Name : "help" ,
209
232
Func : cmdHelp ,
210
233
Usage : "<command>" ,
211
- Short : "Shows help for a Caddy subcommand. " ,
234
+ Short : "Shows help for a Caddy subcommand" ,
212
235
}
213
236
}
214
237
0 commit comments