Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 14:45 UTC
cmd: Custom binary names through `CustomBinaryName` and `CustomLongDescription` (#7513)
Alexandre Daubois committed
Mar 2, 2026 at 12:04 UTC
f283062d37c50627d53ca682ebae2ce219b35515
2 files changed
+42
-4
caddy.go
+28
@@ -945,6 +945,34 @@ func InstanceID() (uuid.UUID, error) {
945
// for example.
946
var CustomVersion string
947
948
+// CustomBinaryName is an optional string that overrides the root
949
+// command name from the default of "caddy". This is useful for
950
+// downstream projects that embed Caddy but use a different binary
951
+// name. Shell completions and help text will use this name instead
952
+// of "caddy".
953
+//
954
+// Set this variable during `go build` with `-ldflags`:
955
+//
956
+// -ldflags '-X github.com/caddyserver/caddy/v2.CustomBinaryName=my_custom_caddy'
957
+//
958
+// for example.
959
+var CustomBinaryName string
960
+
961
+// CustomLongDescription is an optional string that overrides the
962
+// long description of the root Cobra command. This is useful for
963
+// downstream projects that embed Caddy but want different help
964
+// output.
965
+//
966
+// Set this variable in an init() function of a package that is
967
+// imported by your main:
968
+//
969
+// func init() {
970
+// caddy.CustomLongDescription = "My custom server based on Caddy..."
971
+// }
972
+//
973
+// for example.
974
+var CustomLongDescription string
975
+
976
// Version returns the Caddy version in a simple/short form, and
977
// a full version string. The short form will not have spaces and
978
// is intended for User-Agent strings and similar, but may be
cmd/cobra.go
+14
-4
@@ -9,9 +9,14 @@ import (
9
)
10
11
var defaultFactory = newRootCommandFactory(func() *cobra.Command {
12
- return &cobra.Command{
13
- Use: "caddy",
14
- Long: `Caddy is an extensible server platform written in Go.
12
+ bin := caddy.CustomBinaryName
13
+ if bin == "" {
14
+ bin = "caddy"
15
+ }
16
+
17
+ long := caddy.CustomLongDescription
18
+ if long == "" {
19
+ long = `Caddy is an extensible server platform written in Go.
20
21
At its core, Caddy merely manages configuration. Modules are plugged
22
in statically at compile-time to provide useful functionality. Caddy's
@@ -91,7 +96,12 @@ package installers: https://caddyserver.com/docs/install
96
97
Instructions for running Caddy in production are also available:
98
https://caddyserver.com/docs/running
94
-`,
99
+`
100
+ }
101
+
102
+ return &cobra.Command{
103
+ Use: bin,
104
+ Long: long,
105
Example: ` $ caddy run
106
$ caddy run --config caddy.json
107
$ caddy reload --config caddy.json