diff --git a/cli/cmd/context/ls.go b/cli/cmd/context/ls.go index d301f3bc2..a83d8519b 100644 --- a/cli/cmd/context/ls.go +++ b/cli/cmd/context/ls.go @@ -23,12 +23,13 @@ import ( "sort" "strings" + formatter2 "github.com/docker/compose-cli/cmd/formatter" + "github.com/pkg/errors" "github.com/spf13/cobra" apicontext "github.com/docker/compose-cli/api/context" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/mobycli" ) @@ -68,7 +69,7 @@ func runList(cmd *cobra.Command, opts lsOpts) error { return err } format := strings.ToLower(strings.ReplaceAll(opts.format, " ", "")) - if format != "" && format != formatter.JSON && format != formatter.PRETTY && format != formatter.TemplateLegacyJSON { + if format != "" && format != formatter2.JSON && format != formatter2.PRETTY && format != formatter2.TemplateLegacyJSON { mobycli.Exec(cmd.Root()) return nil } @@ -91,15 +92,15 @@ func runList(cmd *cobra.Command, opts lsOpts) error { return nil } - if opts.json || format == formatter.JSON { - opts.format = formatter.JSON + if opts.json || format == formatter2.JSON { + opts.format = formatter2.JSON } - if format == formatter.TemplateLegacyJSON { - opts.format = formatter.TemplateLegacyJSON + if format == formatter2.TemplateLegacyJSON { + opts.format = formatter2.TemplateLegacyJSON } view := viewFromContextList(contexts, currentContext) - return formatter.Print(view, opts.format, os.Stdout, + return formatter2.Print(view, opts.format, os.Stdout, func(w io.Writer) { for _, c := range view { contextName := c.Name diff --git a/cli/cmd/context/rm.go b/cli/cmd/context/rm.go index b6bbde59b..1602c9d4e 100644 --- a/cli/cmd/context/rm.go +++ b/cli/cmd/context/rm.go @@ -20,12 +20,13 @@ import ( "errors" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/hashicorp/go-multierror" "github.com/spf13/cobra" apicontext "github.com/docker/compose-cli/api/context" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" ) type removeOpts struct { diff --git a/cli/cmd/inspect.go b/cli/cmd/inspect.go index e344794c1..8f84f714e 100644 --- a/cli/cmd/inspect.go +++ b/cli/cmd/inspect.go @@ -20,6 +20,8 @@ import ( "context" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/Azure/go-autorest/autorest/to" "github.com/compose-spec/compose-go/types" "github.com/pkg/errors" @@ -27,7 +29,6 @@ import ( "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/containers" - "github.com/docker/compose-cli/cli/formatter" ) // InspectCommand inspects into containers diff --git a/cli/cmd/kill.go b/cli/cmd/kill.go index b836da3ae..be4671521 100644 --- a/cli/cmd/kill.go +++ b/cli/cmd/kill.go @@ -20,12 +20,13 @@ import ( "context" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) diff --git a/cli/cmd/ps.go b/cli/cmd/ps.go index 587999b11..9bfbdd9a4 100644 --- a/cli/cmd/ps.go +++ b/cli/cmd/ps.go @@ -23,12 +23,13 @@ import ( "os" "strings" + formatter3 "github.com/docker/compose-cli/cmd/formatter" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/containers" - formatter2 "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/utils/formatter" ) @@ -89,11 +90,11 @@ func runPs(ctx context.Context, opts psOpts) error { } if opts.json { - opts.format = formatter2.JSON + opts.format = formatter3.JSON } view := viewFromContainerList(containerList) - return formatter2.Print(view, opts.format, os.Stdout, func(w io.Writer) { + return formatter3.Print(view, opts.format, os.Stdout, func(w io.Writer) { for _, c := range view { _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", c.ID, c.Image, c.Command, c.Status, strings.Join(c.Ports, ", ")) diff --git a/cli/cmd/rm.go b/cli/cmd/rm.go index 120d8b577..5f012e1f5 100644 --- a/cli/cmd/rm.go +++ b/cli/cmd/rm.go @@ -20,13 +20,14 @@ import ( "context" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/containers" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) diff --git a/cli/cmd/secrets.go b/cli/cmd/secrets.go index 22a9e934c..45360b7dc 100644 --- a/cli/cmd/secrets.go +++ b/cli/cmd/secrets.go @@ -22,11 +22,12 @@ import ( "io/ioutil" "os" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/secrets" - "github.com/docker/compose-cli/cli/formatter" ) // SecretCommand manage secrets diff --git a/cli/cmd/start.go b/cli/cmd/start.go index 76dada2df..a12e4b109 100644 --- a/cli/cmd/start.go +++ b/cli/cmd/start.go @@ -20,12 +20,13 @@ import ( "context" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) diff --git a/cli/cmd/stop.go b/cli/cmd/stop.go index 8f1c66352..e66587ca3 100644 --- a/cli/cmd/stop.go +++ b/cli/cmd/stop.go @@ -20,12 +20,13 @@ import ( "context" "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) diff --git a/cli/cmd/version.go b/cli/cmd/version.go index f7caa7938..4465cb80f 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -21,10 +21,12 @@ import ( "os" "strings" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/spf13/cobra" "github.com/docker/cli/cli" - "github.com/docker/compose-cli/cli/formatter" + "github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/internal" ) diff --git a/cli/cmd/volume/command.go b/cli/cmd/volume/command.go index cc062c7b4..0aef21ce0 100644 --- a/cli/cmd/volume/command.go +++ b/cli/cmd/volume/command.go @@ -20,11 +20,11 @@ import ( "context" "fmt" + format "github.com/docker/compose-cli/cmd/formatter" + "github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" - format "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/ecs" "github.com/docker/compose-cli/pkg/progress" @@ -125,7 +125,7 @@ func rmVolume() *cobra.Command { } fmt.Println(id) } - formatter.SetMultiErrorFormat(errs) + format.SetMultiErrorFormat(errs) return errs.ErrorOrNil() }, } diff --git a/cli/cmd/volume/list.go b/cli/cmd/volume/list.go index 8bbc20188..38b54fdb2 100644 --- a/cli/cmd/volume/list.go +++ b/cli/cmd/volume/list.go @@ -21,11 +21,12 @@ import ( "io" "os" + formatter2 "github.com/docker/compose-cli/cmd/formatter" + "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/volumes" - "github.com/docker/compose-cli/cli/formatter" ) type listVolumeOpts struct { @@ -55,14 +56,14 @@ func listVolume() *cobra.Command { return nil } view := viewFromVolumeList(vols) - return formatter.Print(view, opts.format, os.Stdout, func(w io.Writer) { + return formatter2.Print(view, opts.format, os.Stdout, func(w io.Writer) { for _, vol := range view { _, _ = fmt.Fprintf(w, "%s\t%s\n", vol.ID, vol.Description) } }, "ID", "DESCRIPTION") }, } - cmd.Flags().StringVar(&opts.format, "format", formatter.PRETTY, "Format the output. Values: [pretty | json]. (Default: pretty)") + cmd.Flags().StringVar(&opts.format, "format", formatter2.PRETTY, "Format the output. Values: [pretty | json]. (Default: pretty)") cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") return cmd } diff --git a/cli/main.go b/cli/main.go index 4a4dd2ca0..2c0025946 100644 --- a/cli/main.go +++ b/cli/main.go @@ -228,7 +228,7 @@ func main() { // On default context, "compose" is implemented by CLI Plugin proxy := api.NewServiceProxy().WithService(service.ComposeService()) - command := compose2.RootCommand(ctype, proxy) + command := compose2.RootCommand(proxy) if ctype == store.AciContextType { customizeCliForACI(command, proxy) diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index 85fa4f7ab..260d5f818 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -25,6 +25,8 @@ import ( "strings" "syscall" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/sirupsen/logrus" "github.com/compose-spec/compose-go/cli" @@ -35,8 +37,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/pkg/compose" ) @@ -198,7 +198,7 @@ func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj } // RootCommand returns the compose command with its child commands -func RootCommand(contextType string, backend api.Service) *cobra.Command { +func RootCommand(backend api.Service) *cobra.Command { opts := projectOptions{} var ( ansi string @@ -247,10 +247,6 @@ func RootCommand(contextType string, backend api.Service) *cobra.Command { opts.ProjectDir = opts.WorkDir fmt.Fprint(os.Stderr, aec.Apply("option '--workdir' is DEPRECATED at root level! Please use '--project-directory' instead.\n", aec.RedF)) } - if contextType == store.DefaultContextType || contextType == store.LocalContextType { - Warning = "The new 'docker compose' command is currently experimental. " + - "To provide feedback or request new features please open issues at https://github.com/docker/compose-cli" - } return nil }, } @@ -262,8 +258,8 @@ func RootCommand(contextType string, backend api.Service) *cobra.Command { restartCommand(&opts, backend), stopCommand(&opts, backend), psCommand(&opts, backend), - listCommand(contextType, backend), - logsCommand(&opts, contextType, backend), + listCommand(backend), + logsCommand(&opts, backend), convertCommand(&opts, backend), killCommand(&opts, backend), runCommand(&opts, backend), @@ -276,17 +272,12 @@ func RootCommand(contextType string, backend api.Service) *cobra.Command { portCommand(&opts, backend), imagesCommand(&opts, backend), versionCommand(), + buildCommand(&opts, backend), + pushCommand(&opts, backend), + pullCommand(&opts, backend), + createCommand(&opts, backend), + copyCommand(&opts, backend), ) - - if contextType == store.LocalContextType || contextType == store.DefaultContextType { - command.AddCommand( - buildCommand(&opts, backend), - pushCommand(&opts, backend), - pullCommand(&opts, backend), - createCommand(&opts, backend), - copyCommand(&opts, backend), - ) - } command.Flags().SetInterspersed(false) opts.addProjectFlags(command.Flags()) command.Flags().StringVar(&ansi, "ansi", "auto", `Control when to print ANSI control characters ("never"|"always"|"auto")`) diff --git a/cmd/compose/images.go b/cmd/compose/images.go index 4da71f7eb..5e0489919 100644 --- a/cmd/compose/images.go +++ b/cmd/compose/images.go @@ -24,11 +24,12 @@ import ( "sort" "strings" + formatter2 "github.com/docker/compose-cli/cmd/formatter" + "github.com/docker/docker/pkg/stringid" "github.com/docker/go-units" "github.com/spf13/cobra" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/pkg/utils" ) @@ -88,7 +89,7 @@ func runImages(ctx context.Context, backend api.Service, opts imageOptions, serv return images[i].ContainerName < images[j].ContainerName }) - return formatter.Print(images, formatter.PRETTY, os.Stdout, + return formatter2.Print(images, formatter2.PRETTY, os.Stdout, func(w io.Writer) { for _, img := range images { id := stringid.TruncateID(img.ID) diff --git a/cmd/compose/list.go b/cmd/compose/list.go index 83b51ceb9..0b1045b6f 100644 --- a/cmd/compose/list.go +++ b/cmd/compose/list.go @@ -23,11 +23,11 @@ import ( "os" "strings" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/docker/cli/opts" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) @@ -38,7 +38,7 @@ type lsOptions struct { Filter opts.FilterOpt } -func listCommand(contextType string, backend api.Service) *cobra.Command { +func listCommand(backend api.Service) *cobra.Command { opts := lsOptions{Filter: opts.NewFilterOpt()} lsCmd := &cobra.Command{ Use: "ls", @@ -51,9 +51,7 @@ func listCommand(contextType string, backend api.Service) *cobra.Command { lsCmd.Flags().StringVar(&opts.Format, "format", "pretty", "Format the output. Values: [pretty | json].") lsCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs.") lsCmd.Flags().Var(&opts.Filter, "filter", "Filter output based on conditions provided.") - if contextType == store.DefaultContextType { - lsCmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Show all stopped Compose projects") - } + lsCmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Show all stopped Compose projects") return lsCmd } diff --git a/cmd/compose/logs.go b/cmd/compose/logs.go index 88ee5d5ba..0d672bd74 100644 --- a/cmd/compose/logs.go +++ b/cmd/compose/logs.go @@ -20,10 +20,10 @@ import ( "context" "os" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" ) @@ -39,7 +39,7 @@ type logsOptions struct { timestamps bool } -func logsCommand(p *projectOptions, contextType string, backend api.Service) *cobra.Command { +func logsCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := logsOptions{ projectOptions: p, } @@ -58,10 +58,7 @@ func logsCommand(p *projectOptions, contextType string, backend api.Service) *co flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.") flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.") flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps.") - - if contextType == store.DefaultContextType { - flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.") - } + flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.") return logsCmd } diff --git a/cmd/compose/ps.go b/cmd/compose/ps.go index 0adc24d86..f86ec0cbd 100644 --- a/cmd/compose/ps.go +++ b/cmd/compose/ps.go @@ -25,11 +25,12 @@ import ( "strconv" "strings" + "github.com/docker/compose-cli/cmd/formatter" + formatter2 "github.com/docker/cli/cli/command/formatter" "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/pkg/utils" ) diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 4cdffa747..a056c83b4 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -23,10 +23,11 @@ import ( "strconv" "strings" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/compose-spec/compose-go/types" "github.com/spf13/cobra" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/pkg/utils" ) diff --git a/cmd/compose/version.go b/cmd/compose/version.go index 676d1cb01..b366a40cf 100644 --- a/cmd/compose/version.go +++ b/cmd/compose/version.go @@ -19,9 +19,10 @@ package compose import ( "fmt" + "github.com/docker/compose-cli/cmd/formatter" + "github.com/spf13/cobra" - "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/internal" ) diff --git a/cli/formatter/colors.go b/cmd/formatter/colors.go similarity index 100% rename from cli/formatter/colors.go rename to cmd/formatter/colors.go diff --git a/cli/formatter/consts.go b/cmd/formatter/consts.go similarity index 100% rename from cli/formatter/consts.go rename to cmd/formatter/consts.go diff --git a/cli/formatter/formatter.go b/cmd/formatter/formatter.go similarity index 100% rename from cli/formatter/formatter.go rename to cmd/formatter/formatter.go diff --git a/cli/formatter/formatter_test.go b/cmd/formatter/formatter_test.go similarity index 100% rename from cli/formatter/formatter_test.go rename to cmd/formatter/formatter_test.go diff --git a/cli/formatter/json.go b/cmd/formatter/json.go similarity index 100% rename from cli/formatter/json.go rename to cmd/formatter/json.go diff --git a/cli/formatter/logs.go b/cmd/formatter/logs.go similarity index 100% rename from cli/formatter/logs.go rename to cmd/formatter/logs.go diff --git a/cli/formatter/multierrformat.go b/cmd/formatter/multierrformat.go similarity index 100% rename from cli/formatter/multierrformat.go rename to cmd/formatter/multierrformat.go diff --git a/cli/formatter/pretty.go b/cmd/formatter/pretty.go similarity index 100% rename from cli/formatter/pretty.go rename to cmd/formatter/pretty.go diff --git a/cmd/main.go b/cmd/main.go index 65bc1d083..af2e64b6a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,17 +23,21 @@ import ( "github.com/docker/cli/cli/command" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/context/store" commands "github.com/docker/compose-cli/cmd/compose" "github.com/docker/compose-cli/internal" "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/pkg/compose" ) +func init() { + commands.Warning = "The new 'docker compose' command is currently experimental. " + + "To provide feedback or request new features please open issues at https://github.com/docker/compose-cli" +} + func main() { plugin.Run(func(dockerCli command.Cli) *cobra.Command { lazyInit := api.NewServiceProxy() - cmd := commands.RootCommand(store.DefaultContextType, lazyInit) + cmd := commands.RootCommand(lazyInit) originalPreRun := cmd.PersistentPreRunE cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { if err := plugin.PersistentPreRunE(cmd, args); err != nil { diff --git a/docs/yaml/main/generate.go b/docs/yaml/main/generate.go index 23fff8ac9..00108de4e 100644 --- a/docs/yaml/main/generate.go +++ b/docs/yaml/main/generate.go @@ -35,7 +35,7 @@ const descriptionSourcePath = "docs/reference/" func generateCliYaml(opts *options) error { cmd := &cobra.Command{Use: "docker"} - cmd.AddCommand(compose.RootCommand("local", nil)) + cmd.AddCommand(compose.RootCommand(nil)) disableFlagsInUseLine(cmd) source := filepath.Join(opts.source, descriptionSourcePath) if err := loadLongDescription(cmd, source); err != nil {