mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
* Allow for argument completion This shows for a single command on how to complete service names in the cluster: `uc inspect <TAB>` will complete using ListServices See: #307 Signed-off-by: Miek Gieben <miek@miek.nl> * All cluster interactions can be completed Signed-off-by: Miek Gieben <miek@miek.nl> * Machines -m flag completion Signed-off-by: Miek Gieben <miek@miek.nl> * Add completion for "ctx use" Signed-off-by: Miek Gieben <miek@miek.nl> * Complete from compose file too Signed-off-by: Miek Gieben <miek@miek.nl> * Allow for argument completion This shows for a single command on how to complete service names in the cluster: `uc inspect <TAB>` will complete using ListServices See: #307 Signed-off-by: Miek Gieben <miek@miek.nl> * All cluster interactions can be completed Signed-off-by: Miek Gieben <miek@miek.nl> * Machines -m flag completion Signed-off-by: Miek Gieben <miek@miek.nl> * Add completion for "ctx use" Signed-off-by: Miek Gieben <miek@miek.nl> * Complete from compose file too Signed-off-by: Miek Gieben <miek@miek.nl> * Move to better place Signed-off-by: Miek Gieben <miek@miek.nl> * Adjust imports Signed-off-by: Miek Gieben <miek@miek.nl> * prefix match for context too Signed-off-by: Miek Gieben <miek@miek.nl> --------- Signed-off-by: Miek Gieben <miek@miek.nl>
31 lines
805 B
Go
31 lines
805 B
Go
package completion
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
|
|
composecli "github.com/compose-spec/compose-go/v2/cli"
|
|
"github.com/psviderski/uncloud/pkg/client/compose"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func ComposeServices(ctx context.Context, args []string, toComplete string, files, profiles []string) ([]cobra.Completion, cobra.ShellCompDirective) {
|
|
project, err := compose.LoadProject(ctx, files, composecli.WithDefaultProfiles(profiles...))
|
|
if err != nil {
|
|
return nil, cobra.ShellCompDirectiveError
|
|
}
|
|
|
|
services := project.ServiceNames()
|
|
names := []cobra.Completion{}
|
|
for _, service := range services {
|
|
if slices.Contains(args, service) {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(service, toComplete) {
|
|
names = append(names, service)
|
|
}
|
|
}
|
|
return names, cobra.ShellCompDirectiveNoFileComp
|
|
}
|