From ba244556b301a437e620de990c52bb88bacaa277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Mon, 16 Aug 2021 12:49:16 +0200 Subject: [PATCH] fix(docs): replace props desc when empty (#197) --- cli/cmd/docs/docs.go | 5 ++- docs/index.md | 8 ++-- pkg/format/render_markdown.go | 11 ++++-- pkg/format/render_markdown_test.go | 59 +++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/cli/cmd/docs/docs.go b/cli/cmd/docs/docs.go index 0a19b0ca..5bfc195f 100644 --- a/cli/cmd/docs/docs.go +++ b/cli/cmd/docs/docs.go @@ -51,8 +51,9 @@ func printDocs(format string, services []string) cli.Result { renderer = f.ConsoleTreeRenderer{WithValues: false} case "markdown": renderer = f.MarkdownTreeRenderer{ - HeaderPrefix: "### ", - PropsDescription: "Props can be either supplied using the params argument, or through the URL using \n`?key=value&key=value` etc.\n", + HeaderPrefix: "### ", + PropsDescription: "Props can be either supplied using the params argument, or through the URL using \n`?key=value&key=value` etc.\n", + PropsEmptyMessage: "*The services does not support any query/param props*", } default: return cli.InvalidUsage("invalid format") diff --git a/docs/index.md b/docs/index.md index 2a472e53..17d5ea54 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ # Shoutrrr
- +

@@ -14,7 +14,7 @@ Heavily inspired by caronc/apprise - codecov + codecov Codacy Badge @@ -28,7 +28,7 @@ Heavily inspired by caronc/apprise github code size in bytes - + license

@@ -37,4 +37,4 @@ Heavily inspired by caronc/apprise 0 { + sb.WriteString(r.PropsDescription) + } else { + sb.WriteString(r.PropsEmptyMessage) + } sb.WriteRune('\n') for _, field := range queryFields { r.writeFieldPrimary(&sb, field) diff --git a/pkg/format/render_markdown_test.go b/pkg/format/render_markdown_test.go index 641a6183..39051f97 100644 --- a/pkg/format/render_markdown_test.go +++ b/pkg/format/render_markdown_test.go @@ -91,8 +91,63 @@ var _ = Describe("RenderMarkdown", func() { Possible values: ` + "`Yes`, `No`, `Maybe`" + ` ` - println() - println(actual) + Expect(actual).To(Equal(expected)) }) + + When("there are no query props", func() { + It("should prepend an empty-message instead of props description", func() { + actual := testRenderTree(MarkdownTreeRenderer{ + HeaderPrefix: `### `, + PropsDescription: "Feel free to set these:", + PropsEmptyMessage: "There is nothing to set!", + }, &struct { + Host string `url:"host"` + }{}) + + expected := ` +### URL Fields + +* __Host__ (**Required**) + URL part: mock://host/ +### Query/Param Props + +There is nothing to set! +`[1:] // Remove initial newline + + //_ = actual == expected + //println() + //println(actual) + Expect(actual).To(Equal(expected)) + }) + }) + + When("there are query props", func() { + It("should prepend the props description", func() { + actual := testRenderTree(MarkdownTreeRenderer{ + HeaderPrefix: `### `, + PropsDescription: "Feel free to set these:", + PropsEmptyMessage: "There is nothing to set!", + }, &struct { + Host string `url:"host"` + CoolMode bool `key:"coolmode" optional:""` + }{}) + + expected := ` +### URL Fields + +* __Host__ (**Required**) + URL part: mock://host/ +### Query/Param Props + +Feel free to set these: +* __CoolMode__ + Default: *empty* + +`[1:] // Remove initial newline + + Expect(actual).To(Equal(expected)) + }) + }) + })