Skip to content

Commit 799c99b

Browse files
committed
Added installed size and summary description in Package
1 parent b8fb384 commit 799c99b

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

apt.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ import (
2424
"fmt"
2525
"os/exec"
2626
"regexp"
27+
"strconv"
2728
"strings"
2829
)
2930

3031
// Package is a package available in the APT system
3132
type Package struct {
32-
Name string
33-
Status string
34-
Architecture string
35-
Version string
33+
Name string
34+
Status string
35+
Architecture string
36+
Version string
37+
ShortDescription string
38+
InstalledSizeKB int
3639
}
3740

3841
// List returns a list of packages available in the system with their
@@ -46,7 +49,7 @@ func List() ([]*Package, error) {
4649
func Search(pattern string) ([]*Package, error) {
4750
res := []*Package{}
4851

49-
cmd := exec.Command("dpkg-query", "-W", "-f=${Package}\t${Architecture}\t${db:Status-Status}\t${Version}\n", "*"+pattern+"*")
52+
cmd := exec.Command("dpkg-query", "-W", "-f=${Package}\t${Architecture}\t${db:Status-Status}\t${Version}\t${Installed-Size}\t${Binary:summary}\n", "*"+pattern+"*")
5053

5154
out, err := cmd.CombinedOutput()
5255
if err != nil {
@@ -60,11 +63,18 @@ func Search(pattern string) ([]*Package, error) {
6063
scanner := bufio.NewScanner(bytes.NewReader(out))
6164
for scanner.Scan() {
6265
data := strings.Split(scanner.Text(), "\t")
66+
size, err := strconv.Atoi(data[4])
67+
if err != nil {
68+
// Ignore error
69+
size = 0
70+
}
6371
res = append(res, &Package{
64-
Name: data[0],
65-
Architecture: data[1],
66-
Status: data[2],
67-
Version: data[3],
72+
Name: data[0],
73+
Architecture: data[1],
74+
Status: data[2],
75+
Version: data[3],
76+
InstalledSizeKB: size,
77+
ShortDescription: data[5],
6878
})
6979
}
7080

0 commit comments

Comments
 (0)