forked from evergreen-ci/evergreen
/
patch_list.go
64 lines (55 loc) · 1.42 KB
/
patch_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
58
59
60
61
62
63
64
package operations
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
func PatchList() cli.Command {
const (
numberFlagName = "number"
showSummaryFlagName = "show-summary"
)
return cli.Command{
Name: "list-patches",
Usage: "show existing patches",
Flags: mergeFlagSlices(addPatchIDFlag(), addVariantsFlag(
cli.IntFlag{
Name: joinFlagNames(numberFlagName, "n"),
Usage: "number of patches to show (0 for all patches)",
Value: 5,
},
cli.BoolFlag{
Name: joinFlagNames(showSummaryFlagName, "s"),
Usage: "show a summary of the diff for each patch",
})),
Action: func(c *cli.Context) error {
confPath := c.Parent().String(confFlagName)
number := c.Int(numberFlagName)
showSummary := c.Bool(showSummaryFlagName)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf, err := NewClientSettings(confPath)
if err != nil {
return errors.Wrap(err, "problem loading configuration")
}
_ = conf.GetRestCommunicator(ctx)
ac, _, err := conf.getLegacyClients()
if err != nil {
return errors.Wrap(err, "problem accessing evergreen service")
}
patches, err := ac.GetPatches(number)
if err != nil {
return err
}
for _, p := range patches {
disp, err := getPatchDisplay(&p, showSummary, conf.UIServerHost)
if err != nil {
return err
}
fmt.Println(disp)
}
return nil
},
}
}