Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringToString usage output is unstable #362

Open
SOF3 opened this issue Oct 7, 2022 · 1 comment · May be fixed by #365
Open

StringToString usage output is unstable #362

SOF3 opened this issue Oct 7, 2022 · 1 comment · May be fixed by #365

Comments

@SOF3
Copy link

SOF3 commented Oct 7, 2022

Since Go maps have randomized iteration order, FlagUsages() returns inconsistent output:

playground

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"

	"github.com/spf13/pflag"
)

func main() {
	counter := map[string]int{}

	for i := 0; i < 100; i++ {
		fs := pflag.NewFlagSet("t", pflag.ExitOnError)
		fs.StringToString("foo", map[string]string{"a": "b", "c": "d"}, "usage")
		output := fs.FlagUsages()
		counter[output]++
	}

	fmt.Print(counter)
}
map[      --foo stringToString   usage (default [a=b,c=d])
:88       --foo stringToString   usage (default [c=d,a=b])
:12]

In projects with a workflow that writes the command usage to a file (e.g. README), this causes unnecessary diff all the time.

@SOF3 SOF3 changed the title StringToString usage print is unstable StringToString usage output is unstable Oct 7, 2022
@twz123
Copy link

twz123 commented Nov 22, 2023

It's a general issue concerning reproducibility. If you want to create an OS package including docs, say, man pages, it won't be reproducible since the man pages will differ on each build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants