Skip to content
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
16 changes: 16 additions & 0 deletions clidocstool.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@ func copyFile(src string, dst string) error {
_, err = io.Copy(df, sf)
return err
}

func getAliases(cmd *cobra.Command) []string {
if len(cmd.Aliases) == 0 {
return cmd.Aliases
}

var parentPath string
if cmd.HasParent() {
parentPath = cmd.Parent().CommandPath() + " "
}
aliases := []string{cmd.CommandPath()}
for _, a := range cmd.Aliases {
aliases = append(aliases, parentPath+a)
}
return aliases
}
8 changes: 3 additions & 5 deletions clidocstool_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
fmt.Fprintf(b, "%s\n\n", desc)
}

if len(cmd.Aliases) != 0 {
fmt.Fprintf(b, "### Aliases\n\n`%s`", cmd.Name())
for _, a := range cmd.Aliases {
fmt.Fprintf(b, ", `%s`", a)
}
if aliases := getAliases(cmd); len(aliases) != 0 {
fmt.Fprint(b, "### Aliases\n\n")
fmt.Fprint(b, "`"+strings.Join(aliases, "`, `")+"`")
fmt.Fprint(b, "\n\n")
}

Expand Down
2 changes: 1 addition & 1 deletion clidocstool_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *Client) genYamlCustom(cmd *cobra.Command, w io.Writer) error {

cliDoc := cmdDoc{
Name: cmd.CommandPath(),
Aliases: strings.Join(cmd.Aliases, ", "),
Aliases: strings.Join(getAliases(cmd), ", "),
Short: forceMultiLine(cmd.Short, shortMaxWidth),
Long: forceMultiLine(cmd.Long, longMaxWidth),
Example: cmd.Example,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/buildx_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Start a build

### Aliases

`build`, `b`
`docker buildx build`, `docker buildx b`

### Options

Expand Down
2 changes: 1 addition & 1 deletion fixtures/docker_buildx_build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
command: docker buildx build
aliases: b
aliases: docker buildx build, docker buildx b
short: Start a build
long: Start a build
usage: docker buildx build [OPTIONS] PATH | URL | -
Expand Down