Fix cyclomatic complexity of two formatters

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-05-09 17:24:40 -04:00 committed by Tonis Tiigi
parent 0c6b8d717d
commit c60d13e539
1 changed files with 42 additions and 39 deletions

View File

@ -65,49 +65,52 @@ reclaimable: {{.Reclaimable}}
} }
func (ctx *DiskUsageContext) Write() (err error) { func (ctx *DiskUsageContext) Write() (err error) {
if !ctx.Verbose { if ctx.Verbose {
ctx.buffer = bytes.NewBufferString("") return ctx.verboseWrite()
ctx.preFormat() }
ctx.buffer = bytes.NewBufferString("")
tmpl, err := ctx.parseFormat() ctx.preFormat()
if err != nil {
return err
}
err = ctx.contextFormat(tmpl, &diskUsageImagesContext{
totalSize: ctx.LayersSize,
images: ctx.Images,
})
if err != nil {
return err
}
err = ctx.contextFormat(tmpl, &diskUsageContainersContext{
containers: ctx.Containers,
})
if err != nil {
return err
}
err = ctx.contextFormat(tmpl, &diskUsageVolumesContext{
volumes: ctx.Volumes,
})
if err != nil {
return err
}
diskUsageContainersCtx := diskUsageContainersContext{containers: []*types.Container{}}
diskUsageContainersCtx.header = map[string]string{
"Type": typeHeader,
"TotalCount": totalHeader,
"Active": activeHeader,
"Size": sizeHeader,
"Reclaimable": reclaimableHeader,
}
ctx.postFormat(tmpl, &diskUsageContainersCtx)
tmpl, err := ctx.parseFormat()
if err != nil {
return err return err
} }
err = ctx.contextFormat(tmpl, &diskUsageImagesContext{
totalSize: ctx.LayersSize,
images: ctx.Images,
})
if err != nil {
return err
}
err = ctx.contextFormat(tmpl, &diskUsageContainersContext{
containers: ctx.Containers,
})
if err != nil {
return err
}
err = ctx.contextFormat(tmpl, &diskUsageVolumesContext{
volumes: ctx.Volumes,
})
if err != nil {
return err
}
diskUsageContainersCtx := diskUsageContainersContext{containers: []*types.Container{}}
diskUsageContainersCtx.header = map[string]string{
"Type": typeHeader,
"TotalCount": totalHeader,
"Active": activeHeader,
"Size": sizeHeader,
"Reclaimable": reclaimableHeader,
}
ctx.postFormat(tmpl, &diskUsageContainersCtx)
return err
}
func (ctx *DiskUsageContext) verboseWrite() (err error) {
// First images // First images
tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat) tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat)
if err != nil { if err != nil {