mirror of
https://github.com/docker/compose.git
synced 2025-07-05 21:04:26 +02:00
Add shell completion for --profile
Signed-off-by: Ariel Bachar <relrelb@users.noreply.github.com> Signed-off-by: relrelb <relrelb@users.noreply.github.com>
This commit is contained in:
parent
80856eacaf
commit
0345461412
@ -17,6 +17,7 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
@ -65,3 +66,23 @@ func completeProjectNames(backend api.Service) func(cmd *cobra.Command, args []s
|
|||||||
return values, cobra.ShellCompDirectiveNoFileComp
|
return values, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func completeProfileNames(p *ProjectOptions) validArgsFn {
|
||||||
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
project, err := p.ToProject(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
|
allProfileNames := project.AllServices().GetProfiles()
|
||||||
|
sort.Strings(allProfileNames)
|
||||||
|
|
||||||
|
var values []string
|
||||||
|
for _, profileName := range allProfileNames {
|
||||||
|
if strings.HasPrefix(profileName, toComplete) {
|
||||||
|
values = append(values, profileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -448,6 +448,10 @@ func RootCommand(streams command.Cli, backend api.Service) *cobra.Command { //no
|
|||||||
return []string{"yaml", "yml"}, cobra.ShellCompDirectiveFilterFileExt
|
return []string{"yaml", "yml"}, cobra.ShellCompDirectiveFilterFileExt
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
c.RegisterFlagCompletionFunc( //nolint:errcheck
|
||||||
|
"profile",
|
||||||
|
completeProfileNames(&opts),
|
||||||
|
)
|
||||||
|
|
||||||
c.Flags().StringVar(&progress, "progress", buildx.PrinterModeAuto, fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
|
c.Flags().StringVar(&progress, "progress", buildx.PrinterModeAuto, fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user