-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added autocompletion for images and system connections for podman image SCP #11153
Conversation
2d86740
to
849fea9
Compare
Can you add this diff: diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index a86d17dda..944b17641 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -323,6 +323,18 @@ func prefixSlice(pre string, slice []string) []string {
return slice
}
+func suffixCompSlice(suf string, slice []string) []string {
+ for i := range slice {
+ split := strings.SplitN(slice[i], "\t", 2)
+ if len(split) > 1 {
+ slice[i] = split[0] + suf + "\t" + split[1]
+ } else {
+ slice[i] = slice[i] + suf
+ }
+ }
+ return slice
+}
+
func completeKeyValues(toComplete string, k keyValueCompletion) ([]string, cobra.ShellCompDirective) {
suggestions := make([]string, 0, len(k))
directive := cobra.ShellCompDirectiveNoFileComp
@@ -669,21 +681,34 @@ func AutocompleteScp(cmd *cobra.Command, args []string, toComplete string) ([]st
if !validCurrentCmdLine(cmd, args, toComplete) {
return nil, cobra.ShellCompDirectiveNoFileComp
}
- connectionSuggestions, _ := AutocompleteSystemConnections(cmd, args, toComplete)
- imageSuggestions, _ := getImages(cmd, toComplete)
switch len(args) {
case 0:
- totalSuggestions := append(connectionSuggestions, imageSuggestions...)
- return totalSuggestions, cobra.ShellCompDirectiveNoFileComp
+ split := strings.SplitN(toComplete, "::", 2)
+ if len(split) > 1 {
+ imageSuggestions, _ := getImages(cmd, split[1])
+ return prefixSlice(split[0]+"::", imageSuggestions), cobra.ShellCompDirectiveNoFileComp
+ }
+ connectionSuggestions, _ := AutocompleteSystemConnections(cmd, args, toComplete)
+ imageSuggestions, _ := getImages(cmd, toComplete)
+ totalSuggestions := append(suffixCompSlice("::", connectionSuggestions), imageSuggestions...)
+ directive := cobra.ShellCompDirectiveNoFileComp
+ // if we have connections do not add a space after the completion
+ if len(connectionSuggestions) > 0 {
+ directive = cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
+ }
+ return totalSuggestions, directive
case 1:
- if strings.Contains(args[0], "::") {
- if len(strings.Split(args[0], "::")[1]) > 0 {
+ split := strings.SplitN(args[0], "::", 2)
+ if len(split) > 1 {
+ if len(split[1]) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
+ imageSuggestions, _ := getImages(cmd, toComplete)
return imageSuggestions, cobra.ShellCompDirectiveNoFileComp
}
- return connectionSuggestions, cobra.ShellCompDirectiveNoFileComp
+ connectionSuggestions, _ := AutocompleteSystemConnections(cmd, args, toComplete)
+ return suffixCompSlice("::", connectionSuggestions), cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveNoFileComp
} The advantages are the it can complete images after |
@Luap99 thanks I was wondering how to complete mid-arg with |
[NO TESTS NEEDED] image scp should autocomplete images and system connections since the args can be either. Made a new function, common.AutocompleteScp Signed-off-by: cdoern <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@rhatdan @TomSweeneyRedHat PTAL, works well now due to Paul's diff on the switch in |
LGTM |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cdoern, Luap99 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
image scp should autocomplete images and system connections since the args can
be either. Made a new function,
common.AutocompleteScp
This function looks at the current arg length and either gives the user a connection name, an image, or nothing depending on what has already been typed.
Signed-off-by: cdoern [email protected]