-
Notifications
You must be signed in to change notification settings - Fork 16
/
list.go
57 lines (55 loc) · 1.65 KB
/
list.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
package deal
import (
"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/cmd/cliutil"
"github.com/data-preservation-programs/singularity/database"
"github.com/data-preservation-programs/singularity/handler/deal"
"github.com/data-preservation-programs/singularity/model"
"github.com/rjNemo/underscore"
"github.com/urfave/cli/v2"
)
var ListCmd = &cli.Command{
Name: "list",
Usage: "List all deals",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "preparation",
Usage: "Filter deals by preparation id or name",
},
&cli.StringSliceFlag{
Name: "source",
Usage: "Filter deals by source storage id or name",
},
&cli.UintSliceFlag{
Name: "schedule",
Usage: "Filter deals by schedule",
},
&cli.StringSliceFlag{
Name: "provider",
Usage: "Filter deals by provider",
},
&cli.StringSliceFlag{
Name: "state",
Usage: "Filter deals by state: proposed, published, active, expired, proposal_expired, slashed",
},
},
Action: func(c *cli.Context) error {
db, closer, err := database.OpenFromCLI(c)
if err != nil {
return errors.WithStack(err)
}
defer closer.Close()
deals, err := deal.Default.ListHandler(c.Context, db, deal.ListDealRequest{
Preparations: c.StringSlice("preparation"),
Sources: c.StringSlice("source"),
Schedules: underscore.Map(c.IntSlice("schedules"), func(i int) uint32 { return uint32(i) }),
Providers: c.StringSlice("provider"),
States: underscore.Map(c.StringSlice("state"), func(s string) model.DealState { return model.DealState(s) }),
})
if err != nil {
return errors.WithStack(err)
}
cliutil.Print(c, deals)
return nil
},
}