Skip to content

Commit 35be9e4

Browse files
Add support for custom binary names through CustomBinaryName and CustomLongDescription
1 parent 1a0f168 commit 35be9e4

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

caddy.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,34 @@ func InstanceID() (uuid.UUID, error) {
929929
// for example.
930930
var CustomVersion string
931931

932+
// CustomBinaryName is an optional string that overrides the root
933+
// command name from the default of "caddy". This is useful for
934+
// downstream projects that embed Caddy but use a different binary
935+
// name. Shell completions and help text will use this name instead
936+
// of "caddy".
937+
//
938+
// Set this variable during `go build` with `-ldflags`:
939+
//
940+
// -ldflags '-X github.com/caddyserver/caddy/v2.CustomBinaryName=my_custom_caddy'
941+
//
942+
// for example.
943+
var CustomBinaryName string
944+
945+
// CustomLongDescription is an optional string that overrides the
946+
// long description of the root Cobra command. This is useful for
947+
// downstream projects that embed Caddy but want different help
948+
// output.
949+
//
950+
// Set this variable in an init() function of a package that is
951+
// imported by your main:
952+
//
953+
// func init() {
954+
// caddy.CustomLongDescription = "My custom server based on Caddy..."
955+
// }
956+
//
957+
// for example.
958+
var CustomLongDescription string
959+
932960
// Version returns the Caddy version in a simple/short form, and
933961
// a full version string. The short form will not have spaces and
934962
// is intended for User-Agent strings and similar, but may be

cmd/cobra.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99
)
1010

1111
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.
1520
1621
At its core, Caddy merely manages configuration. Modules are plugged
1722
in statically at compile-time to provide useful functionality. Caddy's
@@ -91,7 +96,12 @@ package installers: https://caddyserver.com/docs/install
9196
9297
Instructions for running Caddy in production are also available:
9398
https://caddyserver.com/docs/running
94-
`,
99+
`
100+
}
101+
102+
return &cobra.Command{
103+
Use: bin,
104+
Long: long,
95105
Example: ` $ caddy run
96106
$ caddy run --config caddy.json
97107
$ caddy reload --config caddy.json

0 commit comments

Comments
 (0)