From 5bd820d68e6abf767552960d9c7dc904fe0440e1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 20 Dec 2022 18:45:24 +0100 Subject: [PATCH 1/2] markdown: replace new line in usage Signed-off-by: CrazyMax --- clidocstool_md.go | 11 ++++++++++- clidocstool_test.go | 3 ++- fixtures/buildx_build.md | 2 +- fixtures/docker_buildx_build.yaml | 5 +++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clidocstool_md.go b/clidocstool_md.go index 24efee4..326a876 100644 --- a/clidocstool_md.go +++ b/clidocstool_md.go @@ -20,6 +20,7 @@ import ( "log" "os" "path/filepath" + "regexp" "strings" "text/template" @@ -28,6 +29,10 @@ import ( "github.com/spf13/pflag" ) +var ( + nlRegexp = regexp.MustCompile(`\r?\n`) +) + // GenMarkdownTree will generate a markdown page for this command and all // descendants in the directory given. func (c *Client) GenMarkdownTree(cmd *cobra.Command) error { @@ -216,7 +221,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) { } else if cd, ok := cmd.Annotations[annotation.CodeDelimiter]; ok { usage = strings.ReplaceAll(usage, cd, "`") } - fmt.Fprintf(b, "%s | %s | %s | %s |\n", mdEscapePipe(name), mdEscapePipe(ftype), mdEscapePipe(defval), mdEscapePipe(usage)) + fmt.Fprintf(b, "%s | %s | %s | %s |\n", mdEscapePipe(name), mdEscapePipe(ftype), mdEscapePipe(defval), mdReplaceNewline(mdEscapePipe(usage))) }) fmt.Fprintln(b, "") } @@ -227,3 +232,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) { func mdEscapePipe(s string) string { return strings.ReplaceAll(s, `|`, `\|`) } + +func mdReplaceNewline(s string) string { + return nlRegexp.ReplaceAllString(s, "
") +} diff --git a/clidocstool_test.go b/clidocstool_test.go index 6d9e4a5..141bdd6 100644 --- a/clidocstool_test.go +++ b/clidocstool_test.go @@ -118,7 +118,8 @@ func init() { buildxBuildFlags.StringVar(&ignore, "shm-size", "", `Size of "/dev/shm"`) - buildxBuildFlags.StringArray("ssh", []string{}, `SSH agent socket or keys to expose to the build (format: "default|[=|[,]]")`) + buildxBuildFlags.StringArray("ssh", []string{}, `SSH agent socket or keys to expose to the build +format: "default|[=|[,]]"`) buildxBuildFlags.StringArrayP("tag", "t", []string{}, `Name and optionally a tag (format: "name:tag")`) buildxBuildFlags.SetAnnotation("tag", annotation.ExternalURL, []string{"https://docs.docker.com/engine/reference/commandline/build/#tag-an-image--t"}) diff --git a/fixtures/buildx_build.md b/fixtures/buildx_build.md index 1cf0c40..f56c8e4 100644 --- a/fixtures/buildx_build.md +++ b/fixtures/buildx_build.md @@ -29,7 +29,7 @@ Start a build | `-q`, `--quiet` | | | Suppress the build output and print image ID on success | | `--secret` | `stringArray` | | Secret file to expose to the build (format: `id=mysecret,src=/local/secret`) | | `--shm-size` | `string` | | Size of `/dev/shm` | -| `--ssh` | `stringArray` | | SSH agent socket or keys to expose to the build (format: `default\|[=\|[,]]`) | +| `--ssh` | `stringArray` | | SSH agent socket or keys to expose to the build
format: `default\|[=\|[,]]` | | [`-t`](https://docs.docker.com/engine/reference/commandline/build/#tag-an-image--t), [`--tag`](https://docs.docker.com/engine/reference/commandline/build/#tag-an-image--t) | `stringArray` | | Name and optionally a tag (format: `name:tag`) | | [`--target`](https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target) | `string` | | Set the target build stage to build. | | `--ulimit` | `string` | | Ulimit options | diff --git a/fixtures/docker_buildx_build.yaml b/fixtures/docker_buildx_build.yaml index 752775e..b522ff7 100644 --- a/fixtures/docker_buildx_build.yaml +++ b/fixtures/docker_buildx_build.yaml @@ -314,8 +314,9 @@ options: - option: ssh value_type: stringArray default_value: '[]' - description: | - SSH agent socket or keys to expose to the build (format: `default|[=|[,]]`) + description: |- + SSH agent socket or keys to expose to the build + format: `default|[=|[,]]` deprecated: false hidden: false experimental: false From 6de4bc971124abe449a056cad748b9a3b8f196d9 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 20 Dec 2022 18:46:30 +0100 Subject: [PATCH 2/2] readme: fix badge Signed-off-by: CrazyMax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dc8aa9..4d5ee64 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/docker/cli-docs-tool) -[![Test Status](https://img.shields.io/github/workflow/status/docker/cli-docs-tool/test?label=test&logo=github&style=flat-square)](https://github.com/docker/cli-docs-tool/actions?query=workflow%3Atest) +[![Test Status](https://img.shields.io/github/actions/workflow/status/docker/cli-docs-tool/test.yml?branch=main&label=test&logo=github&style=flat-square)](https://github.com/docker/cli-docs-tool/actions?query=workflow%3Atest) [![Go Report Card](https://goreportcard.com/badge/github.com/docker/cli-docs-tool)](https://goreportcard.com/report/github.com/docker/cli-docs-tool) ## About