Skip to content

Commit

Permalink
Hide deprecated shorthand flags in man page generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jun 21, 2016
1 parent 29c0a1f commit 112c7dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/man_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func manPrintFlags(out io.Writer, flags *pflag.FlagSet) {
return
}
format := ""
if len(flag.Shorthand) > 0 {
format = "**-%s**, **--%s**"
if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {
format = fmt.Sprintf("**-%s**, **--%s**", flag.Shorthand, flag.Name)
} else {
format = "%s**--%s**"
format = fmt.Sprintf("**--%s**", flag.Name)
}
if len(flag.NoOptDefVal) > 0 {
format = format + "["
Expand All @@ -149,7 +149,7 @@ func manPrintFlags(out io.Writer, flags *pflag.FlagSet) {
format = format + "]"
}
format = format + "\n\t%s\n\n"
fmt.Fprintf(out, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)
fmt.Fprintf(out, format, flag.DefValue, flag.Usage)
})
}

Expand Down
15 changes: 15 additions & 0 deletions doc/man_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ func TestGenManSeeAlso(t *testing.T) {
}
}

func TestManPrintFlagsHidesShortDeperecated(t *testing.T) {
cmd := &cobra.Command{}
flags := cmd.Flags()
flags.StringP("foo", "f", "default", "Foo flag")
flags.MarkShorthandDeprecated("foo", "don't use it no more")

out := new(bytes.Buffer)
manPrintFlags(out, flags)

expected := "**--foo**=\"default\"\n\tFoo flag\n\n"
if out.String() != expected {
t.Fatalf("Expected %s, but got %s", expected, out.String())
}
}

func AssertLineFound(scanner *bufio.Scanner, expectedLine string) error {
for scanner.Scan() {
line := scanner.Text()
Expand Down

0 comments on commit 112c7dc

Please sign in to comment.