Merge pull request #19539 from dvdksn/cli-reference-tpl-fixups

cli reference template improvements
This commit is contained in:
David Karlsson 2024-03-01 17:02:10 +01:00 committed by GitHub
commit 6a1bb3da95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 82 additions and 57 deletions

View File

@ -94,65 +94,68 @@
{{ . | $.RenderString (dict "display" "block") }}
{{ end }}
{{ with $data.options }}
{{ $heading := dict "level" 2 "text" "Options" }}
{{ partial "heading.html" $heading }}
{{ $.Scratch.Add "headings" $heading }}
<table>
<thead>
<tr>
<th>Option</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{ range where . "hidden" false }}
{{ $opts := where . "hidden" false }}
{{ with $opts }}
{{ $heading := dict "level" 2 "text" "Options" }}
{{ partial "heading.html" $heading }}
{{ $.Scratch.Add "headings" $heading }}
<table>
<thead>
<tr>
{{ $short := .shorthand }}
{{ $long := .option }}
<td>
{{ with .details_url }}
<a class="link" href="{{ . }}">
<code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
</a>
{{ else }}
<code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
{{ end }}
</td>
{{ $skipDefault := `[],map[],false,0,0s,default,'',""` }}
<td>
{{ with .default_value }}
{{ cond (in $skipDefault .) "" (printf "<code>%s</code>" . | safeHTML) }}
{{ end }}
</td>
<td>
{{ with .min_api_version }}
{{ partial "components/badge.html" (dict "color" "blue" "content" (printf "API %s+" .)) }}
{{ end }}
{{ with .deprecated }}
{{ partial "components/badge.html" (dict "color" "red" "content" "Deprecated") }}
{{ end }}
{{ with .experimental }}
{{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (daemon)") }}
{{ end }}
{{ with .experimentalcli }}
{{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (CLI)") }}
{{ end }}
{{ with .kubernetes }}
{{ partial "components/badge.html" (dict "color" "blue" "content" "Kubernetes") }}
{{ end }}
{{ with .swarm }}
{{ partial "components/badge.html" (dict "color" "blue" "content" "Swarm") }}
{{ end }}
{{ if .description }}
{{/* replace newlines in long desc with break tags */}}
{{ markdownify (strings.Replace .description "\n" "<br>") }}
{{ end }}
</td>
<th>Option</th>
<th>Default</th>
<th>Description</th>
</tr>
{{ end }}
</tbody>
</table>
</thead>
<tbody>
{{ range . }}
<tr>
{{ $short := .shorthand }}
{{ $long := .option }}
<td>
{{ with .details_url }}
<a class="link" href="{{ . }}">
<code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
</a>
{{ else }}
<code>{{ with $short }}-{{ . }}, {{end}}--{{ $long }}</code>
{{ end }}
</td>
{{ $skipDefault := `[],map[],false,0,0s,default,'',""` }}
<td>
{{ with .default_value }}
{{ cond (in $skipDefault .) "" (printf "<code>%s</code>" . | safeHTML) }}
{{ end }}
</td>
<td>
{{ with .min_api_version }}
{{ partial "components/badge.html" (dict "color" "blue" "content" (printf "API %s+" .)) }}
{{ end }}
{{ with .deprecated }}
{{ partial "components/badge.html" (dict "color" "red" "content" "Deprecated") }}
{{ end }}
{{ with .experimental }}
{{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (daemon)") }}
{{ end }}
{{ with .experimentalcli }}
{{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (CLI)") }}
{{ end }}
{{ with .kubernetes }}
{{ partial "components/badge.html" (dict "color" "blue" "content" "Kubernetes") }}
{{ end }}
{{ with .swarm }}
{{ partial "components/badge.html" (dict "color" "blue" "content" "Swarm") }}
{{ end }}
{{ if .description }}
{{/* replace newlines in long desc with break tags */}}
{{ markdownify (strings.Replace .description "\n" "<br>") }}
{{ end }}
</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}
{{ end }}
{{ with $data.examples }}
{{ $heading := dict "level" 2 "text" "Examples" }}
@ -166,6 +169,28 @@
{{ end }}
{{ $.RenderString (dict "display" "block") . }}
{{ end }}
{{ if eq .Kind "section" }}
{{ $heading := dict "level" 2 "text" "Subcommands" }}
{{ partial "heading.html" $heading }}
{{ $.Scratch.Add "headings" $heading }}
<table>
<thead>
<tr>
<th class="text-left">Command</th>
<th class="text-left">Description</th>
</tr>
</thead>
<tbody>
{{ range .Pages }}
<tr>
<td class="text-left"><a class="link" href="{{ .Permalink }}"><code>{{ .Title }}</code></a></th>
{{ $data := index (index site.Data .Params.datafolder) .Params.datafile }}
<td class="text-left">{{ $data.short }}</th>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}
</article>
{{ end }}