aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
authorSteve Domino <[email protected]>2015-09-04 16:22:44 -0600
committerSteve Domino <[email protected]>2015-09-07 22:43:34 -0600
commit574bc4cfb94effb3e1bb934f1512c1f1a558000f (patch)
tree9476914f0340b527cea03ff04677bd120151dcb4 /flag_test.go
parent8e7dc108ab3a1ab6ce6d922bbaff5657b88e8e49 (diff)
adding a private field to flags, and a function for marking flags as private
removing some c/p left-overs from the MarkPrivate function, and updating the comment slightly changed field from Private to Hidden. Added documentation w/example to README.md. Added testing to confirm hidden flags updating test message
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go
index 165f689..1b4005c 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -831,3 +831,35 @@ func TestMultipleNormalizeFlagNameInvocations(t *testing.T) {
t.Fatal("Expected normalizeFlagNameInvocations to be 1; got ", normalizeFlagNameInvocations)
}
}
+
+//
+func TestHiddenFlagInUsage(t *testing.T) {
+ f := NewFlagSet("bob", ContinueOnError)
+ f.Bool("secretFlag", true, "shhh")
+ f.MarkHidden("secretFlag")
+
+ out := new(bytes.Buffer)
+ f.SetOutput(out)
+ f.PrintDefaults()
+
+ if strings.Contains(out.String(), "secretFlag") {
+ t.Errorf("found hidden flag in usage!")
+ }
+}
+
+//
+func TestHiddenFlagUsage(t *testing.T) {
+ f := NewFlagSet("bob", ContinueOnError)
+ f.Bool("secretFlag", true, "shhh")
+ f.MarkHidden("secretFlag")
+
+ args := []string{"--secretFlag"}
+ out, err := parseReturnStderr(t, f, args)
+ if err != nil {
+ t.Fatal("expected no error; got ", err)
+ }
+
+ if strings.Contains(out, "shhh") {
+ t.Errorf("usage message printed when using a hidden flag!")
+ }
+}