add output format for status
This commit is contained in:
1 parent
63735cde1d
commit
51f6ed4c70
6 files changed
+32
-20
No files matched your search
+23
-15
@@ -25,6 +25,9 @@ func Status() cli.Command {
|
||||
Name: "status",
|
||||
Usage: "get available configs",
|
||||
Action: status.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrintStatus,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,22 +43,27 @@ func (statusCommand) action(ctx *cli.Context) {
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
utils.PrintError(err)
|
||||
} else {
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
||||
for _, module := range arrayOfModules {
|
||||
addresses := ""
|
||||
connection := tableNotConnectedStatus
|
||||
instanceList := make([]string, 0, len(module.Status))
|
||||
for _, value := range module.Status {
|
||||
instanceList = append(instanceList, fmt.Sprintf("%s %s", value.Address.GetAddress(), value.Version))
|
||||
switch ctx.String(flag.OutPrintStatus.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
utils.PrintAnswer(arrayOfModules)
|
||||
default:
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
||||
for _, module := range arrayOfModules {
|
||||
addresses := ""
|
||||
connection := tableNotConnectedStatus
|
||||
instanceList := make([]string, 0, len(module.Status))
|
||||
for _, value := range module.Status {
|
||||
instanceList = append(instanceList, fmt.Sprintf("%s %s", value.Address.GetAddress(), value.Version))
|
||||
}
|
||||
addresses = strings.Join(instanceList, "\n")
|
||||
if addresses != "" {
|
||||
connection = tableConnectedStatus
|
||||
}
|
||||
table.Append([]string{module.Name, connection, addresses})
|
||||
}
|
||||
addresses = strings.Join(instanceList, "\n")
|
||||
if addresses != "" {
|
||||
connection = tableConnectedStatus
|
||||
}
|
||||
table.Append([]string{module.Name, connection, addresses})
|
||||
table.Render()
|
||||
}
|
||||
table.Render()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user