Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate long desc and examples for root command #53

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions clidocstool.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,33 @@ func (c *Client) GenAllTree() error {
}

// loadLongDescription gets long descriptions and examples from markdown.
func (c *Client) loadLongDescription(parentCmd *cobra.Command, generator string) error {
for _, cmd := range parentCmd.Commands() {
if cmd.HasSubCommands() {
if err := c.loadLongDescription(cmd, generator); err != nil {
func (c *Client) loadLongDescription(cmd *cobra.Command, generator string) error {
if cmd.HasSubCommands() {
for _, sub := range cmd.Commands() {
if err := c.loadLongDescription(sub, generator); err != nil {
return err
}
}
name := cmd.CommandPath()
if i := strings.Index(name, " "); i >= 0 {
// remove root command / binary name
name = name[i+1:]
}
if name == "" {
continue
}
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
sourcePath := filepath.Join(c.source, mdFile)
content, err := os.ReadFile(sourcePath)
if os.IsNotExist(err) {
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
continue
}
if err != nil {
return err
}
applyDescriptionAndExamples(cmd, string(content))
}
name := cmd.CommandPath()
if i := strings.Index(name, " "); i >= 0 {
// remove root command / binary name
name = name[i+1:]
}
if name == "" {
return nil
}
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
sourcePath := filepath.Join(c.source, mdFile)
content, err := os.ReadFile(sourcePath)
if os.IsNotExist(err) {
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
return nil
}
if err != nil {
return err
}
applyDescriptionAndExamples(cmd, string(content))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion clidocstool_man_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestGenManTree(t *testing.T) {
c, err := New(Options{
Root: dockerCmd,
SourceDir: tmpdir,
Plugin: true,
Plugin: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these changes needed? (Just curious as I couldn't immediately associate with the change in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ManHeader: &doc.GenManHeader{
Title: "DOCKER",
Section: "1",
Expand Down
2 changes: 1 addition & 1 deletion clidocstool_md_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGenMarkdownTree(t *testing.T) {
c, err := New(Options{
Root: dockerCmd,
SourceDir: tmpdir,
Plugin: true,
Plugin: false,
})
require.NoError(t, err)
require.NoError(t, c.GenMarkdownTree(dockerCmd))
Expand Down
7 changes: 6 additions & 1 deletion clidocstool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func setup() {
DisableFlagsInUseLine: true,
}

dockerCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
dockerCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
dockerCmd.PersistentFlags().Lookup("help").Hidden = true
dockerCmd.Flags().StringP("host", "H", "unix:///var/run/docker.sock", "Daemon socket to connect to")

attachCmd = &cobra.Command{
Use: "attach [OPTIONS] CONTAINER",
Short: "Attach local standard input, output, and error streams to a running container",
Expand Down Expand Up @@ -237,7 +242,7 @@ func TestGenAllTree(t *testing.T) {
c, err := New(Options{
Root: dockerCmd,
SourceDir: tmpdir,
Plugin: true,
Plugin: false,
ManHeader: &doc.GenManHeader{
Title: "DOCKER",
Section: "1",
Expand Down
2 changes: 1 addition & 1 deletion clidocstool_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGenYamlTree(t *testing.T) {
c, err := New(Options{
Root: dockerCmd,
SourceDir: tmpdir,
Plugin: true,
Plugin: false,
})
require.NoError(t, err)
require.NoError(t, c.GenYamlTree(dockerCmd))
Expand Down
4 changes: 0 additions & 4 deletions fixtures/docker-attach.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Attach local standard input, output, and error streams to a running container
\fB--detach-keys\fP=""
Override the key sequence for detaching a container

.PP
\fB-h\fP, \fB--help\fP[=false]
help for attach

.PP
\fB--no-stdin\fP[=false]
Do not attach STDIN
Expand Down
4 changes: 0 additions & 4 deletions fixtures/docker-buildx-build.1
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ Start a build
\fB-f\fP, \fB--file\fP=""
Name of the Dockerfile (default: "PATH/Dockerfile")

.PP
\fB-h\fP, \fB--help\fP[=false]
help for build

.PP
\fB--iidfile\fP=""
Write the image ID to the file
Expand Down
4 changes: 0 additions & 4 deletions fixtures/docker-buildx-dial-stdio.1
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ Proxy current stdio streams to builder instance


.SH OPTIONS
.PP
\fB-h\fP, \fB--help\fP[=false]
help for dial-stdio

.PP
\fB--platform\fP=""
Target platform: this is used for node selection
Expand Down
6 changes: 0 additions & 6 deletions fixtures/docker-buildx-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ docker-buildx-install - Install buildx as a 'docker builder' alias
Install buildx as a 'docker builder' alias


.SH OPTIONS
.PP
\fB-h\fP, \fB--help\fP[=false]
help for install


.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
\fB--builder\fP=""
Expand Down
6 changes: 0 additions & 6 deletions fixtures/docker-buildx-stop.1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ docker-buildx-stop - Stop builder instance
Stop builder instance


.SH OPTIONS
.PP
\fB-h\fP, \fB--help\fP[=false]
help for stop


.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
\fB--builder\fP=""
Expand Down
4 changes: 0 additions & 4 deletions fixtures/docker-buildx.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Extended build capabilities with BuildKit
\fB--builder\fP=""
Override the configured builder instance

.PP
\fB-h\fP, \fB--help\fP[=false]
help for buildx


.SH SEE ALSO
.PP
Expand Down
27 changes: 27 additions & 0 deletions fixtures/docker.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.nh
.TH "DOCKER" "1" "Jan 2020" "Docker Community" "Docker User Manuals"

.SH NAME
.PP
docker - A self-sufficient runtime for containers


.SH SYNOPSIS
.PP
\fBdocker [OPTIONS] COMMAND [ARG...]\fP


.SH DESCRIPTION
.PP
A self-sufficient runtime for containers


.SH OPTIONS
.PP
\fB-H\fP, \fB--host\fP="unix:///var/run/docker.sock"
Daemon socket to connect to


.SH SEE ALSO
.PP
\fBdocker-attach(1)\fP, \fBdocker-buildx(1)\fP
22 changes: 22 additions & 0 deletions fixtures/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# docker
dvdksn marked this conversation as resolved.
Show resolved Hide resolved

<!---MARKER_GEN_START-->
A self-sufficient runtime for containers

### Subcommands

| Name | Description |
|:----------------------|:------------------------------------------------------------------------------|
| [`attach`](attach.md) | Attach local standard input, output, and error streams to a running container |
| [`buildx`](buildx.md) | Docker Buildx |


### Options

| Name | Type | Default | Description |
|:---------------|:---------|:------------------------------|:----------------------------|
| `-H`, `--host` | `string` | `unix:///var/run/docker.sock` | Daemon socket to connect to |


<!---MARKER_GEN_END-->

39 changes: 39 additions & 0 deletions fixtures/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
command: docker
dvdksn marked this conversation as resolved.
Show resolved Hide resolved
short: A self-sufficient runtime for containers
long: A self-sufficient runtime for containers
usage: docker [OPTIONS] COMMAND [ARG...]
cname:
- docker attach
- docker buildx
clink:
- docker_attach.yaml
- docker_buildx.yaml
options:
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: host
shorthand: H
value_type: string
default_value: unix:///var/run/docker.sock
description: Daemon socket to connect to
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false

11 changes: 11 additions & 0 deletions fixtures/docker_attach.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
inherited_options:
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down
11 changes: 11 additions & 0 deletions fixtures/docker_buildx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
inherited_options:
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down
10 changes: 10 additions & 0 deletions fixtures/docker_buildx_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ inherited_options:
experimentalcli: false
kubernetes: false
swarm: false
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down
10 changes: 10 additions & 0 deletions fixtures/docker_buildx_dial-stdio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ inherited_options:
experimentalcli: false
kubernetes: false
swarm: false
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down
10 changes: 10 additions & 0 deletions fixtures/docker_buildx_install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ inherited_options:
experimentalcli: false
kubernetes: false
swarm: false
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: true
experimental: false
Expand Down
10 changes: 10 additions & 0 deletions fixtures/docker_buildx_stop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ inherited_options:
experimentalcli: false
kubernetes: false
swarm: false
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down