forked from kopia/kopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_logs_list.go
More file actions
51 lines (38 loc) · 1.1 KB
/
Copy pathcommand_logs_list.go
File metadata and controls
51 lines (38 loc) · 1.1 KB
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
package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/units"
"github.com/kopia/kopia/repo"
)
type commandLogsList struct {
out textOutput
crit logSelectionCriteria
}
func (c *commandLogsList) setup(svc appServices, parent commandParent) {
cmd := parent.Command("list", "List logs.").Alias("ls")
cmd.Action(svc.directRepositoryReadAction(c.run))
c.out.setup(svc)
c.crit.setup(cmd)
}
func (c *commandLogsList) run(ctx context.Context, rep repo.DirectRepository) error {
allSessions0, err := getLogSessions(ctx, rep.BlobReader())
if err != nil {
return errors.Wrap(err, "error getting log sessions")
}
allSessions := c.crit.filterLogSessions(allSessions0)
if len(allSessions) < len(allSessions0) {
defer log(ctx).Infof("NOTE: Listed %v/%v log sessions, pass --all to show all.", len(allSessions), len(allSessions0))
}
// output sessions
for _, s := range allSessions {
c.out.printStdout(
"%v %v %v %v %v\n", s.id,
formatTimestamp(s.startTime),
s.endTime.Sub(s.startTime),
units.BytesString(s.totalSize),
len(s.segments),
)
}
return nil
}