formatter package heavy refactoring

- make it possible to extract the formatter implementation from the
  "common" code, that way, the formatter package stays small
- extract some formatter into their own packages

This is essentially moving the "formatter" implementation of each type
in their respective packages. The *main* reason to do that, is to be
able to depend on `cli/command/formatter` without depending of the
implementation detail of the formatter. As of now, depending on
`cli/command/formatter` means we depend on `docker/docker/api/types`,
`docker/licensing`, … — that should not be the case. `formatter`
should hold the common code (or helpers) to easily create formatter,
not all formatter implementations.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2018-10-23 17:05:44 +02:00
parent ea836abed5
commit 69fdd2a4ad
75 changed files with 750 additions and 711 deletions

View File

@ -4,7 +4,7 @@ import (
"context"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/stack/formatter"
"github.com/docker/cli/cli/compose/convert"
"github.com/docker/docker/api/types"
"github.com/pkg/errors"

View File

@ -5,8 +5,8 @@ import (
"fmt"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/service"
"github.com/docker/cli/cli/command/stack/formatter"
"github.com/docker/cli/cli/command/stack/options"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
@ -29,7 +29,7 @@ func RunServices(dockerCli command.Cli, opts options.Services) error {
return nil
}
info := map[string]formatter.ServiceListInfo{}
info := map[string]service.ListInfo{}
if !opts.Quiet {
taskFilter := filters.NewArgs()
for _, service := range services {
@ -60,7 +60,7 @@ func RunServices(dockerCli command.Cli, opts options.Services) error {
servicesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewServiceListFormat(format, opts.Quiet),
Format: service.NewListFormat(format, opts.Quiet),
}
return formatter.ServiceListWrite(servicesCtx, services, info)
return service.ListFormatWrite(servicesCtx, services, info)
}