-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtopologysync_list.go
More file actions
69 lines (59 loc) · 1.95 KB
/
topologysync_list.go
File metadata and controls
69 lines (59 loc) · 1.95 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package topologysync
import (
"fmt"
"sort"
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
"github.com/stackvista/stackstate-cli/internal/printer"
)
func ListCommand(deps *di.Deps) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Lists active Topology Synchronizations",
Long: "Lists active Topology Synchronizations.",
RunE: deps.CmdRunEWithApi(RunListCommand),
}
return cmd
}
func FormatSyncTable(streams []stackstate_api.TopologyStreamListItem) printer.TableData {
data := make([][]interface{}, len(streams))
for i, stream := range streams {
identifier := "-"
if stream.SyncIdentifier.IsSet() {
identifier = *stream.SyncIdentifier.Get()
}
data[i] = []interface{}{
stream.NodeId,
stream.Name,
identifier,
fmt.Sprintf("+%-4d %5s", stream.CreatedComponents, fmt.Sprintf("-%d", stream.DeletedComponents)),
fmt.Sprintf("+%-4d %5s", stream.CreatedRelations, fmt.Sprintf("-%d", stream.DeletedRelations)),
stream.Errors,
}
}
return printer.TableData{
Header: []string{"Id", "Name", "Identifier", "Components", "Relations", "Errors"},
Data: data,
MissingTableDataMsg: printer.NotFoundMsg{Types: "synchronizations"},
}
}
func RunListCommand(cmd *cobra.Command, cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo) common.CLIError {
streamList, resp, err := api.TopologySynchronizationApi.GetTopologySynchronizationStreams(cli.Context).Execute()
if err != nil {
return common.NewResponseError(err, resp)
}
streams := streamList.Streams
sort.SliceStable(streams, func(i, j int) bool {
return streams[i].Name < streams[j].Name
})
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"synchronizations": streams,
})
} else {
cli.Printer.Table(FormatSyncTable(streams))
}
return nil
}