mirror of
https://github.com/spf13/cobra
synced 2024-12-26 22:37:08 +00:00
YAML documentation contains "Usage" (#1037)
This commit is contained in:
parent
1d3ac910d4
commit
ed7b60e298
2 changed files with 16 additions and 0 deletions
|
@ -37,6 +37,7 @@ type cmdDoc struct {
|
|||
Name string
|
||||
Synopsis string `yaml:",omitempty"`
|
||||
Description string `yaml:",omitempty"`
|
||||
Usage string `yaml:",omitempty"`
|
||||
Options []cmdOption `yaml:",omitempty"`
|
||||
InheritedOptions []cmdOption `yaml:"inherited_options,omitempty"`
|
||||
Example string `yaml:",omitempty"`
|
||||
|
@ -98,6 +99,10 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) str
|
|||
yamlDoc.Synopsis = forceMultiLine(cmd.Short)
|
||||
yamlDoc.Description = forceMultiLine(cmd.Long)
|
||||
|
||||
if cmd.Runnable() {
|
||||
yamlDoc.Usage = cmd.UseLine()
|
||||
}
|
||||
|
||||
if len(cmd.Example) > 0 {
|
||||
yamlDoc.Example = cmd.Example
|
||||
}
|
||||
|
|
|
@ -57,6 +57,17 @@ func TestGenYamlTree(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGenYamlDocRunnable(t *testing.T) {
|
||||
// Testing a runnable command: should contain the "usage" field
|
||||
buf := new(bytes.Buffer)
|
||||
if err := GenYaml(rootCmd, buf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := buf.String()
|
||||
|
||||
checkStringContains(t, output, "usage: "+rootCmd.Use)
|
||||
}
|
||||
|
||||
func BenchmarkGenYamlToFile(b *testing.B) {
|
||||
file, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue