Install shared reporting flags

This commit is contained in:
2026-10-26 02:50:54 +00:00
parent 6ba9338c0a
commit f3bd6dc2ae
10 changed files with 226 additions and 10 deletions

View File

@@ -0,0 +1,28 @@
package commandmeta
import "testing"
func TestReportingFlagsAreBooleanAndReturnedIndependently(t *testing.T) {
flags := ReportingFlags()
want := []string{"quiet", "verbose", "debug", "progress"}
if len(flags) != len(want) {
t.Fatalf("reporting flags = %#v", flags)
}
for index, name := range want {
if flags[index].Name != name || !flags[index].Boolean || flags[index].Short != "" || flags[index].Default != "false" {
t.Errorf("reporting flag %d = %#v", index, flags[index])
}
if !IsReportingFlag(name) {
t.Errorf("%q is not recognized as a reporting flag", name)
}
}
flags[0].Name = "changed"
if ReportingFlags()[0].Name != "quiet" {
t.Fatal("caller mutation changed shared reporting metadata")
}
for _, name := range []string{"help", "quietly", ""} {
if IsReportingFlag(name) {
t.Errorf("%q was incorrectly recognized as a reporting flag", name)
}
}
}