Hide deprecated shorthand flags in man page generation.
This commit is contained in:
		@ -131,10 +131,10 @@ func manPrintFlags(out io.Writer, flags *pflag.FlagSet) {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		format := ""
 | 
							format := ""
 | 
				
			||||||
		if len(flag.Shorthand) > 0 {
 | 
							if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {
 | 
				
			||||||
			format = "**-%s**, **--%s**"
 | 
								format = fmt.Sprintf("**-%s**, **--%s**", flag.Shorthand, flag.Name)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			format = "%s**--%s**"
 | 
								format = fmt.Sprintf("**--%s**", flag.Name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if len(flag.NoOptDefVal) > 0 {
 | 
							if len(flag.NoOptDefVal) > 0 {
 | 
				
			||||||
			format = format + "["
 | 
								format = format + "["
 | 
				
			||||||
@ -149,7 +149,7 @@ func manPrintFlags(out io.Writer, flags *pflag.FlagSet) {
 | 
				
			|||||||
			format = format + "]"
 | 
								format = format + "]"
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		format = format + "\n\t%s\n\n"
 | 
							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)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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 {
 | 
					func AssertLineFound(scanner *bufio.Scanner, expectedLine string) error {
 | 
				
			||||||
	for scanner.Scan() {
 | 
						for scanner.Scan() {
 | 
				
			||||||
		line := scanner.Text()
 | 
							line := scanner.Text()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user