diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index 89002f062f3..160b20eea06 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -29,15 +29,16 @@ import ( "github.com/compose-spec/compose-go/types" dockercli "github.com/docker/cli/cli" "github.com/docker/cli/cli-plugins/manager" - "github.com/docker/compose/v2/cmd/formatter" "github.com/morikuni/aec" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/docker/compose/v2/cmd/formatter" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/compose" + "github.com/docker/compose/v2/pkg/utils" ) // Command defines a compose CLI command as a func with args @@ -218,7 +219,8 @@ const PluginName = "compose" // RunningAsStandalone detects when running as a standalone program func RunningAsStandalone() bool { - return len(os.Args) < 2 || os.Args[1] != manager.MetadataSubcommandName && os.Args[1] != PluginName + rootCommands := []string{manager.MetadataSubcommandName, cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd} + return len(os.Args) < 2 || !utils.StringContains(rootCommands, os.Args[1]) } // RootCommand returns the compose command with its child commands @@ -310,6 +312,29 @@ func RootCommand(backend api.Service) *cobra.Command { ) command.Flags().SetInterspersed(false) opts.addProjectFlags(command.Flags()) + command.RegisterFlagCompletionFunc( + "project-name", + func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + list, err := backend.List(cmd.Context(), api.ListOptions{ + All: true, + }) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + var values []string + for _, stack := range list { + values = append(values, stack.Name) + } + return values, cobra.ShellCompDirectiveNoFileComp + }, + ) + command.RegisterFlagCompletionFunc( + "file", + func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"yaml", "yml"}, cobra.ShellCompDirectiveFilterFileExt + }, + ) + command.Flags().StringVar(&ansi, "ansi", "auto", `Control when to print ANSI control characters ("never"|"always"|"auto")`) command.Flags().BoolVarP(&version, "version", "v", false, "Show the Docker Compose version information") command.Flags().MarkHidden("version") //nolint:errcheck diff --git a/cmd/main.go b/cmd/main.go index 957910a33c7..298c9978cd9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -61,9 +61,10 @@ func pluginMain() { return cmd }, manager.Metadata{ - SchemaVersion: "0.1.0", + SchemaVersion: "0.2.0", Vendor: "Docker Inc.", Version: internal.Version, + Completions: true, }) } diff --git a/go.mod b/go.mod index a43f3fd59b5..1cd9f2318bd 100644 --- a/go.mod +++ b/go.mod @@ -136,7 +136,7 @@ require ( // (for buildx) replace ( - github.com/docker/cli => github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible + github.com/docker/cli => github.com/ndeloof/cli v0.0.0-20220225144918-5a64693e331f github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220121014307-40bb9831756f+incompatible go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939 go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace => github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace v0.0.0-20210714055410-d010b05b4939 diff --git a/go.sum b/go.sum index 8a42c9601f4..b0297ef34dc 100644 --- a/go.sum +++ b/go.sum @@ -498,8 +498,6 @@ github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e/go.mo github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/docker/buildx v0.7.1 h1:l2DlW8YDbB3pH2bUFY5Q9pPQdhd42wqlnO5hoyWrjYM= github.com/docker/buildx v0.7.1/go.mod h1:PzxALHhYWPNhw/8JajPOJBkvx1w2tgOnppL4ESg0wOY= -github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible h1:CaaxCD/l9Dxogu6lxf7AQautlv3sHULrasPadayp0fM= -github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli-docs-tool v0.2.1 h1:ffZhhdws6kE+dCKHLMlYROZz8z01RtWbz+g4xz0eBIU= github.com/docker/cli-docs-tool v0.2.1/go.mod h1:rgW5KKdNpLMBIuH4WQ/1RNh38nH+/Ay5jgL4P0ZMPpY= github.com/docker/compose-on-kubernetes v0.4.19-0.20190128150448-356b2919c496/go.mod h1:iT2pYfi580XlpaV4KmK0T6+4/9+XoKmk/fhoDod1emE= @@ -1145,6 +1143,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+ github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c= github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= +github.com/ndeloof/cli v0.0.0-20220225144918-5a64693e331f h1:dMT6eSYpTfaglXvWZrpEeRdfxwNJq23vmY2mdwuWl7s= +github.com/ndeloof/cli v0.0.0-20220225144918-5a64693e331f/go.mod h1:wxmb4t3v3ZwISBr3B/B631+3VJe+erAxkl3vXQwXj2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= diff --git a/pkg/compose/build.go b/pkg/compose/build.go index bc3d61f1d58..1dfb0a5c4c1 100644 --- a/pkg/compose/build.go +++ b/pkg/compose/build.go @@ -209,13 +209,14 @@ func (s *composeService) doBuild(ctx context.Context, project *types.Project, op if len(opts) == 0 { return nil, nil } - serverInfo, err := s.serverInfo(ctx) - if err != nil { - return nil, err - } - if buildkitEnabled, err := command.BuildKitEnabled(serverInfo); err != nil || !buildkitEnabled { - return s.doBuildClassic(ctx, opts) - } + // TODO depend on https://github.com/docker/cli/pull/3435 & https://github.com/docker/compose/pull/9198 + //serverInfo, err := s.serverInfo(ctx) + //if err != nil { + // return nil, err + //} + //if buildkitEnabled, err := command.BuildKitEnabled(serverInfo); err != nil || !buildkitEnabled { + // return s.doBuildClassic(ctx, opts) + //} return s.doBuildBuildkit(ctx, project, opts, mode) }