From ed4d8e89a083d56741f342ac97a305342764d859 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Fri, 18 Aug 2023 18:26:35 +0200 Subject: [PATCH] feat:[close #78]: Add more info to abroot status command, plus a `--dump` add unstaged packages --- cmd/status.go | 54 +++++++++++++++++++++++++++++------------------- core/packages.go | 18 ++++++++++++++++ locales/en.yml | 2 ++ 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/cmd/status.go b/cmd/status.go index d73d7519..19fb81d8 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -105,32 +105,38 @@ func status(cmd *cobra.Command, args []string) error { if err != nil { return err } + pkgsUnstg, err := pkgMng.GetUnstagedPackagesPlain() + if err != nil { + return err + } if jsonFlag || dumpFlag { type status struct { - Present string `json:"present"` - Future string `json:"future"` - CnfFile string `json:"cnfFile"` - CPU string `json:"cpu"` - GPU []string `json:"gpu"` - Memory string `json:"memory"` - ABImage core.ABImage `json:"abimage"` - Kargs string `json:"kargs"` - PkgsAdd []string `json:"pkgsAdd"` - PkgsRm []string `json:"pkgsRm"` + Present string `json:"present"` + Future string `json:"future"` + CnfFile string `json:"cnfFile"` + CPU string `json:"cpu"` + GPU []string `json:"gpu"` + Memory string `json:"memory"` + ABImage core.ABImage `json:"abimage"` + Kargs string `json:"kargs"` + PkgsAdd []string `json:"pkgsAdd"` + PkgsRm []string `json:"pkgsRm"` + PkgsUnstg []string `json:"pkgsUnstg"` } s := status{ - Present: present.Label, - Future: future.Label, - CnfFile: settings.CnfFileUsed, - CPU: specs.CPU, - GPU: specs.GPU, - Memory: specs.Memory, - ABImage: *abImage, - Kargs: kargs, - PkgsAdd: pkgsAdd, - PkgsRm: pkgsRm, + Present: present.Label, + Future: future.Label, + CnfFile: settings.CnfFileUsed, + CPU: specs.CPU, + GPU: specs.GPU, + Memory: specs.Memory, + ABImage: *abImage, + Kargs: kargs, + PkgsAdd: pkgsAdd, + PkgsRm: pkgsRm, + PkgsUnstg: pkgsUnstg, } b, err := json.Marshal(s) @@ -210,6 +216,11 @@ func status(cmd *cobra.Command, args []string) error { formattedGPU += fmt.Sprintf("\n\t\t- %s", gpu) } + unstagedAlert := "" + if len(pkgsUnstg) > 0 { + unstagedAlert = fmt.Sprintf(abroot.Trans("status.unstagedFoundMsg"), len(pkgsUnstg)) + } + cmdr.Info.Printf( abroot.Trans("status.infoMsg"), present.Label, future.Label, @@ -217,7 +228,8 @@ func status(cmd *cobra.Command, args []string) error { specs.CPU, formattedGPU, specs.Memory, abImage.Digest, abImage.Timestamp.Format("2006-01-02 15:04:05"), abImage.Image, kargs, - strings.Join(pkgsAdd, ", "), strings.Join(pkgsRm, ", "), + strings.Join(pkgsAdd, ", "), strings.Join(pkgsRm, ", "), strings.Join(pkgsUnstg, ", "), + unstagedAlert, ) return nil diff --git a/core/packages.go b/core/packages.go index 90f28275..49572528 100644 --- a/core/packages.go +++ b/core/packages.go @@ -227,6 +227,24 @@ func (p *PackageManager) GetUnstagedPackages() ([]UnstagedPackage, error) { return unstagedList, nil } +// GetUnstagedPackagesPlain returns the package changes that are yet to be applied +// as strings +func (p *PackageManager) GetUnstagedPackagesPlain() ([]string, error) { + PrintVerbose("PackageManager.GetUnstagedPackagesPlain: running...") + pkgs, err := p.GetUnstagedPackages() + if err != nil { + PrintVerbose("PackageManager.GetUnstagedPackagesPlain:err: " + err.Error()) + return nil, err + } + + unstagedList := []string{} + for _, pkg := range pkgs { + unstagedList = append(unstagedList, pkg.Name) + } + + return unstagedList, nil +} + // ClearUnstagedPackages removes all packages from the unstaged list func (p *PackageManager) ClearUnstagedPackages() error { PrintVerbose("PackageManager.ClearUnstagedPackages: running...") diff --git a/locales/en.yml b/locales/en.yml index c7585d30..066687ef 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -69,6 +69,8 @@ status: Packages: - Added: %s - Removed: %s + - Unstaged: %s%s + unstagedFoundMsg: "\n\t\tThere are %d unstaged packages. Please run 'abroot pkg apply' to apply them." dumpMsg: "Dumped ABRoot status to %s\n" upgrade: