Skip to content

Commit

Permalink
docker: use ActionCarapaceBin
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 24, 2022
1 parent 428078e commit 3ef4454
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 72 deletions.
24 changes: 0 additions & 24 deletions completers/docker_completer/cmd/buildx.go

This file was deleted.

24 changes: 0 additions & 24 deletions completers/docker_completer/cmd/compose.go

This file was deleted.

34 changes: 34 additions & 0 deletions completers/docker_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package cmd

import (
"regexp"
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/cmd/carapace/cmd/completers"
"github.com/rsteube/carapace-bin/pkg/actions/bridge"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,6 +43,35 @@ func init() {
"tlscert": carapace.ActionFiles(),
"tlskey": carapace.ActionFiles(),
})

carapace.Gen(rootCmd).PreRun(func(cmd *cobra.Command, args []string) {
r := regexp.MustCompile(`^ (?P<plugin>[^ ]+)[*] +(?P<description>.*)$`)
if output, err := (carapace.Context{}).Command("docker", "--help").Output(); err == nil {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if matches := r.FindStringSubmatch(line); len(matches) > 2 {
name := matches[1]
description := matches[2]
pluginCmd := &cobra.Command{
Use: name,
Short: description,
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagParsing: true,
}

if d := completers.Description("docker-" + name); d != "" {
pluginCmd.Short = d
}

carapace.Gen(pluginCmd).PositionalAnyCompletion(
bridge.ActionCarapaceBin("docker-" + name),
)

rootCmd.AddCommand(pluginCmd)
}
}
}
})
}

func rootAlias(cmd *cobra.Command, initCompletion func(cmd *cobra.Command, isAlias bool)) {
Expand Down
24 changes: 0 additions & 24 deletions completers/docker_completer/cmd/scan.go

This file was deleted.

0 comments on commit 3ef4454

Please sign in to comment.