manpage generation: Make sure parent in SEE ALSO has dashes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
The CommandPath() for a parent might have a space (if .Parent() != .Root()) so we need to replace those spaces with `-`
authored by Eric Paris · committed by Eric Paris · parent 68f5a81 · Browse files · 3 files·+35 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+35 added−32 removed
- other:+35 added−32 removed
Provenance
- Commit
cfecf13- Tree
6becac7- Author
Eric Paris <eparis@redhat.com>- Committer
Eric Paris <eparis@redhat.com>- Parent
68f5a81
3 files changed+35 added−32 removed
modified:cobra_test.go+17 added-9 removed
253 unmodified lines254 fmt.Fprintf(out, "Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)255 t.Errorf(out.String())256 }257 258+func checkStringContains(t *testing.T, found, expected string) {259+ if !strings.Contains(found, expected) {260+ logErr(t, found, expected)261+ }262+}263+264 func checkResultContains(t *testing.T, x resulter, check string) {259- if !strings.Contains(x.Output, check) {260- logErr(t, x.Output, check)265+ checkStringContains(t, x.Output, check)266+}267+268+func checkStringOmits(t *testing.T, found, expected string) {269+ if strings.Contains(found, expected) {270+ logErr(t, found, expected)271 }272 }273 274 func checkResultOmits(t *testing.T, x resulter, check string) {265- if strings.Contains(x.Output, check) {266- logErr(t, x.Output, check)275+ checkStringOmits(t, x.Output, check)267- }276 }277 278 func checkOutputContains(t *testing.T, c *Command, check string) {279 buf := new(bytes.Buffer)703 unmodified lines983 984 func TestAddTemplateFunctions(t *testing.T) {985 AddTemplateFunc("t", func() bool { return true })986 AddTemplateFuncs(template.FuncMap{979- "f": func() bool { return false }, 980- "h": func() string { return "Hello," }, 987+ "f": func() bool { return false },988+ "h": func() string { return "Hello," },989 "w": func() string { return "world." }})990 991 const usage = "Hello, world."984- 992+993 c := &Command{}994 c.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)987- 995+996 if us := c.UsageString(); us != usage {997 t.Errorf("c.UsageString() != \"%s\", is \"%s\"", usage, us)998 }999 }modified:man_docs_test.go+15 added-22 removed
26 unmodified lines27 // We generate on a subcommand so we have both subcommands and parents28 cmdEcho.GenMan("PROJECT", out)29 found := out.String()30 31+ // Make sure parent has - in CommandPath() in SEE ALSO:32+ parentPath := cmdEcho.Parent().CommandPath()33+ dashParentPath := strings.Replace(parentPath, " ", "-", -1)34+ expected := translate(dashParentPath)35+ expected = expected + "(1)"36+ checkStringContains(t, found, expected)37+38 // Our description32- expected := translate(cmdEcho.Name())33- if !strings.Contains(found, expected) {34- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)35- }39+ expected = translate(cmdEcho.Name())40+ checkStringContains(t, found, expected)41 42 // Better have our example43 expected = translate(cmdEcho.Name())39- if !strings.Contains(found, expected) {40- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)41- }44+ checkStringContains(t, found, expected)45 46 // A local flag47 expected = "boolone"45- if !strings.Contains(found, expected) {46- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)47- }48+ checkStringContains(t, found, expected)49 50 // persistent flag on parent51 expected = "rootflag"51- if !strings.Contains(found, expected) {52- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)53- }52+ checkStringContains(t, found, expected)53 54 // We better output info about our parent55 expected = translate(cmdRootWithRun.Name())57- if !strings.Contains(found, expected) {58- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)59- }56+ checkStringContains(t, found, expected)57 58 // And about subcommands59 expected = translate(cmdEchoSub.Name())63- if !strings.Contains(found, expected) {64- t.Errorf("Unexpected response.\nExpecting to contain: \n %q\nGot:\n %q\n", expected, found)65- }60+ checkStringContains(t, found, expected)61 62 unexpected := translate(cmdDeprecated.Name())68- if strings.Contains(found, unexpected) {69- t.Errorf("Unexpected response.\nFound: %v\nBut should not have!!\n", unexpected)70- }63+ checkStringOmits(t, found, unexpected)64 }modified:man_docs.go+3 added-1 removed
143 unmodified lines144 145 if cmd.hasSeeAlso() {146 fmt.Fprintf(buf, "# SEE ALSO\n")147 if cmd.HasParent() {148+ parentPath := cmd.Parent().CommandPath()149+ dashParentPath := strings.Replace(parentPath, " ", "-", -1)148- fmt.Fprintf(buf, "**%s(1)**, ", cmd.Parent().CommandPath())150+ fmt.Fprintf(buf, "**%s(1)**, ", dashParentPath)151 }152 153 children := cmd.Commands()154 sort.Sort(byName(children))12 unmodified lines