-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstatus.go
104 lines (91 loc) · 2.99 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2016, Ben Morgan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
package main
import (
"github.com/cassava/repoctl/internal/term"
"github.com/cassava/repoctl/pacman/aur"
"github.com/spf13/cobra"
)
var (
statusAUR bool
statusMissing bool
statusCached bool
)
func init() {
MainCmd.AddCommand(statusCmd)
statusCmd.Flags().BoolVarP(&statusAUR, "aur", "a", false, "check AUR for upgrades")
statusCmd.Flags().BoolVarP(&statusMissing, "missing", "m", false, "highlight packages missing in AUR")
statusCmd.Flags().BoolVarP(&statusCached, "cached", "c", false, "show how many old package files are cached")
}
var statusCmd = &cobra.Command{
Use: "status [--aur]",
Short: "Show pending changes and packages that can be upgraded",
Long: `Show pending changes to the database and packages that can be updated.
In particular, the following is shown:
"updated": database entries that can be updated/added (new package files)
"obsolete": package files that can be deleted (or backed up)
"cached": package files that are cached (contrary to obsolete)
"removal": database entries that should be deleted (no package files)
"upgrade": packages with updates in AUR (only with -a)
"!aur": packages unavailable in AUR (only with -m)
`,
Args: cobra.ExactArgs(0),
ValidArgsFunction: completeNoFiles,
PreRunE: ProfileInit,
PostRunE: ProfileTeardown,
RunE: func(cmd *cobra.Command, args []string) error {
exceptQuiet()
term.Printf("On repo @{!y}%s\n\n", Repo.Name())
pkgs, err := Repo.ReadMeta(nil)
if err != nil {
return err
}
ignore := Repo.IgnoreMap()
if statusAUR || statusMissing {
err = pkgs.ReadAUR()
if err != nil && !aur.IsNotFound(err) {
return err
}
}
// We assume that there is nothing to do, and if there is,
// then this is set to false.
var nothing = true
for _, p := range pkgs {
var flags []string
if p.HasUpgrade() && !ignore[p.Name] {
flags = append(flags, term.Formatter.Sprintf("@gupgrade(@|%s -> %s@g)", p.Version(), p.AUR.Version))
}
if p.HasUpdate() {
flags = append(flags, term.Formatter.Sprintf("@gupdated(@|%s -> %s@g)", p.VersionRegistered(), p.Version()))
}
if !p.HasFiles() {
flags = append(flags, term.Formatter.Sprint("@rremoval"))
}
if o := p.Obsolete(); len(o) > 0 {
if Repo.IsObsoleteCached() {
if statusCached {
flags = append(flags, term.Formatter.Sprintf("@ycached(@|%d@y)", len(o)))
}
} else {
flags = append(flags, term.Formatter.Sprintf("@yobsolete(@|%d@y)", len(o)))
}
}
if statusMissing && p.AUR == nil && !ignore[p.Name] {
flags = append(flags, term.Formatter.Sprint("@y!aur"))
}
if len(flags) > 0 {
nothing = false
term.Printf(" %s:", p.Name)
for _, f := range flags {
term.Printf(" %s", f)
}
term.Println()
}
}
if nothing {
term.Printf("Everything up-to-date.\n")
}
return nil
},
}