Skip to content

Commit

Permalink
Merge pull request #32 from thaJeztah/custom_aliases
Browse files Browse the repository at this point in the history
use custom annotation for aliases
  • Loading branch information
thaJeztah committed Jul 4, 2022
2 parents d27dd0c + 15a6d25 commit 77abede
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions clidocstool.go
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"io"
"os"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -99,6 +100,13 @@ func copyFile(src string, dst string) error {
}

func getAliases(cmd *cobra.Command) []string {
if a := cmd.Annotations["aliases"]; a != "" {
aliases := strings.Split(a, ",")
for i := 0; i < len(aliases); i++ {
aliases[i] = strings.TrimSpace(aliases[i])
}
return aliases
}
if len(cmd.Aliases) == 0 {
return cmd.Aliases
}
Expand Down
3 changes: 3 additions & 0 deletions clidocstool_test.go
Expand Up @@ -58,6 +58,9 @@ func init() {
Aliases: []string{"b"},
Short: "Start a build",
Run: func(cmd *cobra.Command, args []string) {},
Annotations: map[string]string{
"aliases": "docker image build, docker buildx build, docker buildx b, docker build",
},
}
buildxStopCmd = &cobra.Command{
Use: "stop [NAME]",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/buildx_build.md
Expand Up @@ -5,7 +5,7 @@ Start a build

### Aliases

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

### Options

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

0 comments on commit 77abede

Please sign in to comment.