From 24c4bde14aa3a4fd39ea7fa0478bcdd8f74e6bec Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 28 Feb 2024 00:53:57 +0100 Subject: feat(packages): finished implementing packages install promises --- stdlib/os/debian/apt.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'stdlib') diff --git a/stdlib/os/debian/apt.go b/stdlib/os/debian/apt.go index 63ce497..2eb58fa 100644 --- a/stdlib/os/debian/apt.go +++ b/stdlib/os/debian/apt.go @@ -7,6 +7,7 @@ import ( "log/slog" "os" "os/exec" + "strings" "git.adyxax.org/adyxax/gonf/v2/gonf" "git.adyxax.org/adyxax/gonf/v2/stdlib/os/systemd" @@ -32,21 +33,19 @@ func Promise() { systemd.Promise() } -func packages_install(names []string) gonf.Status { - allKept := true - for _, n := range names { - if _, ok := packages[n]; !ok { - allKept = false - } - } - if allKept { - return gonf.KEPT +func packages_install(names []string) (gonf.Status, []string) { + gonf.FilterSlice(&names, func(n string) bool { + _, ok := packages[n] + return !ok + }) + if len(names) == 0 { + return gonf.KEPT, nil } args := append([]string{"install", "-y", "--no-install-recommends"}, names...) cmd := gonf.CommandWithEnv([]string{"DEBIAN_FRONTEND=noninteractive", "LC_ALL=C"}, "apt-get", args...) cmd.Resolve() packages_list() - return cmd.Status + return cmd.Status, names } func packages_list() { -- cgit v1.2.3