Fix the docs generation to be more deterministic

This was failing the unit tests sometimes otherwise,
due to the default value for log_file being changed.
pull/10909/head
Anders F Björklund 2021-03-24 07:46:47 +01:00
parent f567893cdb
commit 360771ce84
2 changed files with 19 additions and 0 deletions

View File

@ -56,6 +56,9 @@ func DocForCommand(command *cobra.Command) (string, error) {
if err := generateTitle(command, buf); err != nil {
return "", errors.Wrap(err, "generating title")
}
if err := rewriteLogFile(); err != nil {
return "", errors.Wrap(err, "rewriting log_file")
}
if err := rewriteFlags(command); err != nil {
return "", errors.Wrap(err, "rewriting flags")
}

View File

@ -20,8 +20,24 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// rewriteLogFile resets the magic "log_file" flag
// otherwise it starts out under $TMP somewhere
// and shows up as Changed, to default value ""
func rewriteLogFile() error {
flag := pflag.Lookup("log_file")
if flag != nil {
// don't show the default value
err := pflag.Set("log_file", "")
if err != nil {
return err
}
}
return nil
}
type rewrite struct {
flag string
usage string