Skip to content

Commit

Permalink
feat:[close #78]: Add more info to abroot status command, plus a `--d…
Browse files Browse the repository at this point in the history
…ump`

add unstaged packages
  • Loading branch information
mirkobrombin committed Aug 18, 2023
1 parent c87ef96 commit ed4d8e8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
54 changes: 33 additions & 21 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -210,14 +216,20 @@ 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,
settings.CnfFileUsed,
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
Expand Down
18 changes: 18 additions & 0 deletions core/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ed4d8e8

Please sign in to comment.