mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Refactor formatter.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
9b0aaccf55
commit
c8336743a4
14 changed files with 381 additions and 590 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue