Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 900341a

Browse files
Merge pull request #301 from vdemeester/add-completion-cmd
Add a completion sub-command to generate completion for bash
2 parents fb2c2af + 64be0cc commit 900341a

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ Usage:
225225
docker-app [command]
226226
227227
Available Commands:
228+
completion Generates bash completion scripts
228229
deploy Deploy or update an application
229230
helm Generate a Helm chart
230-
help Help about any command
231231
init Start building a Docker application
232232
inspect Shows metadata and settings for a given application
233233
ls List applications.

cmd/docker-app/completion.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"github.com/docker/cli/cli/command"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func completionCmd(dockerCli command.Cli, rootCmd *cobra.Command) *cobra.Command {
9+
return &cobra.Command{
10+
Use: "completion",
11+
Short: "Generates bash completion scripts",
12+
Long: `To load completion run
13+
14+
. <(docker-app completion)
15+
16+
To configure your bash shell to load completions for each session add to your bashrc
17+
18+
# ~/.bashrc or ~/.profile
19+
. <(docker-app completion)
20+
`,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
rootCmd.GenBashCompletion(dockerCli.Out())
23+
},
24+
}
25+
}

cmd/docker-app/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
5454
splitCmd(),
5555
validateCmd(),
5656
versionCmd(dockerCli),
57+
completionCmd(dockerCli, cmd),
5758
)
5859
if internal.Experimental == "on" {
5960
cmd.AddCommand(

0 commit comments

Comments
 (0)