Skip to content
Myr

Hide deprecated shorthand flags in man page generation.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Nephin · committed by Daniel Nephin · parent 29c0a1f · Browse files · 2 files+19 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−4 removed

  • other:+19 added−4 removed

2 files+19 added−4 removed

modified:doc/man_docs_test.go+15 added
127 unmodified lines
128 t.Fatal(fmt.Errorf("Second line after SEE ALSO wasn't correct: %s", err.Error()))129 }130}131132func TestManPrintFlagsHidesShortDeperecated(t *testing.T) {133 cmd := &cobra.Command{}134 flags := cmd.Flags()135 flags.StringP("foo", "f", "default", "Foo flag")136 flags.MarkShorthandDeprecated("foo", "don't use it no more")137138 out := new(bytes.Buffer)139 manPrintFlags(out, flags)140141 expected := "**--foo**=\"default\"\n\tFoo flag\n\n"142 if out.String() != expected {143 t.Fatalf("Expected %s, but got %s", expected, out.String())144 }145}146147func AssertLineFound(scanner *bufio.Scanner, expectedLine string) error {148 for scanner.Scan() {149 line := scanner.Text()150 if line == expectedLine {
26 unmodified lines
modified:doc/man_docs.go+4 added-4 removed
129 unmodified lines
130 if len(flag.Deprecated) > 0 || flag.Hidden {131 return132 }133 format := ""134 if len(flag.Shorthand) > 0 {135 format = "**-%s**, **--%s**"134 if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {135 format = fmt.Sprintf("**-%s**, **--%s**", flag.Shorthand, flag.Name)136 } else {137 format = "%s**--%s**"137 format = fmt.Sprintf("**--%s**", flag.Name)138 }139 if len(flag.NoOptDefVal) > 0 {140 format = format + "["141 }
6 unmodified lines
148 if len(flag.NoOptDefVal) > 0 {149 format = format + "]"150 }151 format = format + "\n\t%s\n\n"152 fmt.Fprintf(out, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)152 fmt.Fprintf(out, format, flag.DefValue, flag.Usage)153 })154}155156func manPrintOptions(out io.Writer, command *cobra.Command) {
60 unmodified lines