Refactor formatter.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: c8336743a47216f87956b77449bd21714d3c45f1
Component: engine
This commit is contained in:
Daniel Nephin
2016-09-12 16:59:18 -04:00
parent d3ee804f34
commit d90a93ce88
14 changed files with 381 additions and 590 deletions

View File

@ -50,35 +50,27 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
func runList(dockerCli *command.DockerCli, opts listOptions) error {
client := dockerCli.Client()
options := types.NetworkListOptions{Filters: opts.filter.Value()}
networkResources, err := client.NetworkList(context.Background(), options)
if err != nil {
return err
}
f := opts.format
if len(f) == 0 {
format := opts.format
if len(format) == 0 {
if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet {
f = dockerCli.ConfigFile().NetworksFormat
format = dockerCli.ConfigFile().NetworksFormat
} else {
f = "table"
format = "table"
}
}
sort.Sort(byNetworkName(networkResources))
networksCtx := formatter.NetworkContext{
Context: formatter.Context{
Output: dockerCli.Out(),
Format: f,
Quiet: opts.quiet,
Trunc: !opts.noTrunc,
},
Networks: networkResources,
networksCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewNetworkFormat(format, opts.quiet),
Trunc: !opts.noTrunc,
}
networksCtx.Write()
return nil
return formatter.NetworkWrite(networksCtx, networkResources)
}