-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skeleton to adopt Cobra completion v2
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
- Loading branch information
Showing
160 changed files
with
6,895 additions
and
3,052 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/docker/cli/cli/command" | ||
"github.com/docker/cli/cli/context/store" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func registerCompletionFuncForGlobalFlags(dockerCli *command.DockerCli, cmd *cobra.Command) { | ||
cmd.RegisterFlagCompletionFunc( | ||
"context", | ||
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
names, err := store.Names(dockerCli.ContextStore()) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
|
||
return filterForCompletion(names, toComplete), cobra.ShellCompDirectiveDefault | ||
}, | ||
) | ||
cmd.RegisterFlagCompletionFunc( | ||
"log-level", | ||
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
values := []string{"debug", "info", "warn", "error", "fatal"} | ||
return filterForCompletion(values, toComplete), cobra.ShellCompDirectiveDefault | ||
}, | ||
) | ||
} | ||
|
||
func filterForCompletion(values []string, toComplete string) []string { | ||
var offer []string | ||
for _, v := range values { | ||
if strings.HasPrefix(v, toComplete) { | ||
offer = append(offer, v) | ||
} | ||
} | ||
return offer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.