Skip to content

Commit

Permalink
Merge pull request #2171 from rsteube/docker-compose-completion
Browse files Browse the repository at this point in the history
docker-compose: added completions
  • Loading branch information
rsteube authored Jan 12, 2024
2 parents b416911 + 8b2cf7f commit 8f2e4d6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions completers/docker-compose_completer/cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker-compose_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -19,4 +20,8 @@ func init() {
attachCmd.Flags().Bool("no-stdin", false, "Do not attach STDIN")
attachCmd.Flags().Bool("sig-proxy", false, "Proxy all received signals to the process")
rootCmd.AddCommand(attachCmd)

carapace.Gen(attachCmd).PositionalCompletion(
action.ActionServices(attachCmd).FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/docker-compose_completer/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
rootCmd.AddCommand(createCmd)

carapace.Gen(createCmd).FlagCompletion(carapace.ActionMap{
"pull": carapace.ActionValues("always", "missing", "never").StyleF(style.ForKeyword),
"pull": carapace.ActionValues("always", "missing", "never", "build").StyleF(style.ForKeyword),
})

carapace.Gen(createCmd).PositionalAnyCompletion(
Expand Down
7 changes: 7 additions & 0 deletions completers/docker-compose_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
"github.com/rsteube/carapace/pkg/traverse"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -43,6 +45,11 @@ func init() {
"ansi": carapace.ActionValues("auto", "never", "always").StyleF(style.ForKeyword),
"env-file": carapace.ActionFiles(),
"file": carapace.ActionFiles(),
"progress": carapace.ActionValues("auto", "tty", "plain", "quiet"),
"project-directory": carapace.ActionDirectories(),
})

carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
return action.ChdirF(traverse.Flag(rootCmd.Flag("project-directory")))
})
}
12 changes: 12 additions & 0 deletions completers/docker-compose_completer/cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker-compose_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -16,4 +17,15 @@ func init() {

scaleCmd.Flags().Bool("no-deps", false, "Don't start linked services.")
rootCmd.AddCommand(scaleCmd)

carapace.Gen(scaleCmd).PositionalAnyCompletion(
carapace.ActionMultiPartsN("=", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return action.ActionServices(scaleCmd).Suffix("=")
default:
return carapace.ActionValues()
}
}),
)
}
5 changes: 5 additions & 0 deletions completers/docker-compose_completer/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker-compose_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -19,4 +20,8 @@ func init() {
statsCmd.Flags().Bool("no-stream", false, "Disable streaming stats and only pull the first result")
statsCmd.Flags().Bool("no-trunc", false, "Do not truncate output")
rootCmd.AddCommand(statsCmd)

carapace.Gen(statsCmd).PositionalCompletion(
action.ActionServices(statsCmd),
)
}
5 changes: 5 additions & 0 deletions completers/docker-compose_completer/cmd/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker-compose_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -16,4 +17,8 @@ func init() {

waitCmd.Flags().Bool("down-project", false, "Drops project when the first container stops")
rootCmd.AddCommand(waitCmd)

carapace.Gen(waitCmd).PositionalAnyCompletion(
action.ActionServices(waitCmd).FilterArgs(),
)
}
5 changes: 5 additions & 0 deletions completers/docker-compose_completer/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/docker-compose_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -17,4 +18,8 @@ func init() {
watchCmd.Flags().Bool("no-up", false, "Do not build & start services before watching")
watchCmd.Flags().Bool("quiet", false, "hide build output")
rootCmd.AddCommand(watchCmd)

carapace.Gen(watchCmd).PositionalAnyCompletion(
action.ActionServices(watchCmd).FilterArgs(),
)
}

0 comments on commit 8f2e4d6

Please sign in to comment.