PrintPackageList shows package list with specified format or default representation
(result *deb.PackageList, format, prefix string)
| 39 | |
| 40 | // PrintPackageList shows package list with specified format or default representation |
| 41 | func PrintPackageList(result *deb.PackageList, format, prefix string) error { |
| 42 | result.PrepareIndex() |
| 43 | |
| 44 | if format == "" { |
| 45 | return result.ForEachIndexed(func(p *deb.Package) error { |
| 46 | context.Progress().Printf(prefix+"%s\n", p) |
| 47 | return nil |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | formatTemplate, err := template.New("format").Parse(format) |
| 52 | if err != nil { |
| 53 | return fmt.Errorf("error parsing -format template: %s", err) |
| 54 | } |
| 55 | |
| 56 | return result.ForEachIndexed(func(p *deb.Package) error { |
| 57 | b := &bytes.Buffer{} |
| 58 | err = formatTemplate.Execute(b, p.ExtendedStanza()) |
| 59 | if err != nil { |
| 60 | return fmt.Errorf("error applying template: %s", err) |
| 61 | } |
| 62 | context.Progress().Printf(prefix+"%s\n", b.String()) |
| 63 | return nil |
| 64 | }) |
| 65 | |
| 66 | } |
| 67 | |
| 68 | // LookupOption checks boolean flag with default (usually config) and command-line |
| 69 | // setting |
no test coverage detected