From: Peymaneh Date: Sat, 14 Jan 2023 17:54:50 +0100 Subject: Add variable for reproducible manpage time stamps --- cmd/commands.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/cmd/commands.go +++ b/cmd/commands.go @@ -21,6 +21,7 @@ "regexp" "strings" "sync" + "time" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" @@ -28,6 +29,14 @@ "github.com/caddyserver/caddy/v2" ) +// CustomDate will be used by the cobra manpage generator to generate a +// reproducible timestamp. If the "Date" header passed to cobra is empty, it +// will derive the time at build time, which is not reproducible. +// can be passed to during `go build` with `-ldflags`: +// +// -ldflags '-X github.com/caddyserver/caddy/v2/cmd.CustomDate=DD.MM.YYYY' +var CustomDate string + // Command represents a subcommand. Name, Func, // and Short are required. type Command struct { @@ -427,7 +436,16 @@ if err := os.MkdirAll(dir, 0o755); err != nil { return caddy.ExitCodeFailedQuit, err } - if err := doc.GenManTree(rootCmd, &doc.GenManHeader{ + if CustomDate != "" { + date, _ := time.Parse(time.RFC3339, CustomDate) + if err := doc.GenManTree(rootCmd, &doc.GenManHeader{ + Title: "Caddy", + Section: "8", // https://en.wikipedia.org/wiki/Man_page#Manual_sections + Date: &date, + }, dir); err != nil { + return caddy.ExitCodeFailedQuit, err + } + } else if err := doc.GenManTree(rootCmd, &doc.GenManHeader{ Title: "Caddy", Section: "8", // https://en.wikipedia.org/wiki/Man_page#Manual_sections }, dir); err != nil {