Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc/rest_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -123,7 +124,14 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
buf.WriteString("\n")
}
if !cmd.DisableAutoGenTag {
buf.WriteString("*Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "*\n")
now := time.Now()
if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" {
unixEpoch, err := strconv.ParseInt(epoch, 10, 64)
if err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec, if the variable is poorly formatted, we should return an error.
Can you handle it like it is done here
https://github.com/spf13/cobra/blob/4f9ef8cdbbc88c5302be95e0e67fd78ebbfa9dd2/doc/man_docs.go#L129C4-L131C5

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the code simpler, because in practice, the variable is either unset or valid and we have used this simplification in other places.
But if you insist, we can copy the approach from man_docs. Is code-duplication okay or should it moved out somehow somewhere (I'm not so familiar with golang)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a shared function doc/util.go

now = time.Unix(unixEpoch, 0)
}
}
buf.WriteString("*Auto generated by spf13/cobra on " + now.Format("2-Jan-2006") + "*\n")
}
_, err := buf.WriteTo(w)
return err
Expand Down
Loading