diff --git a/clidocstool.go b/clidocstool.go index 7f1b8a0..d4aeaba 100644 --- a/clidocstool.go +++ b/clidocstool.go @@ -18,6 +18,7 @@ import ( "errors" "io" "os" + "strings" "github.com/spf13/cobra" ) @@ -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 } diff --git a/clidocstool_test.go b/clidocstool_test.go index 2c50733..6d9e4a5 100644 --- a/clidocstool_test.go +++ b/clidocstool_test.go @@ -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]", diff --git a/fixtures/buildx_build.md b/fixtures/buildx_build.md index 7248112..1cf0c40 100644 --- a/fixtures/buildx_build.md +++ b/fixtures/buildx_build.md @@ -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 diff --git a/fixtures/docker_buildx_build.yaml b/fixtures/docker_buildx_build.yaml index 0268d3d..752775e 100644 --- a/fixtures/docker_buildx_build.yaml +++ b/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 | -