Skip to content

Commit

Permalink
markdown: replace new line in usage
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Dec 20, 2022
1 parent 77abede commit 86b1b31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion clidocstool_md.go
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"

Expand Down Expand Up @@ -216,7 +217,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, "")
}
Expand All @@ -227,3 +228,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 regexp.MustCompile(`\r\n?|\n`).ReplaceAllString(s, "<br>")
}
3 changes: 2 additions & 1 deletion clidocstool_test.go
Expand Up @@ -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|<id>[=<socket>|<key>[,<key>]]")`)
buildxBuildFlags.StringArray("ssh", []string{}, `SSH agent socket or keys to expose to the build
format: "default|<id>[=<socket>|<key>[,<key>]]"`)

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"})
Expand Down
2 changes: 1 addition & 1 deletion fixtures/buildx_build.md
Expand Up @@ -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\|<id>[=<socket>\|<key>[,<key>]]`) |
| `--ssh` | `stringArray` | | SSH agent socket or keys to expose to the build<br>format: `default\|<id>[=<socket>\|<key>[,<key>]]` |
| [`-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 |
Expand Down

0 comments on commit 86b1b31

Please sign in to comment.