Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
wrap column at some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
hico-horiuchi committed Feb 24, 2016
1 parent 59d5b23 commit 41d15f8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ohgi/aggregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ func GetAggregatesCheckIssued(api *sensu.API, check string, issued string, summa
aggregate, err := api.GetAggregatesCheckIssued(check, i, summarize, results)
checkError(err)

table := newUitable()
if summarize != "" {
table := newUitable(true)
if summarize == "output" {
for output, j := range aggregate.Outputs {
table.AddRow(
bold(strings.Replace(output, "\n", " ", -1)),
bold(formatOutput(output)+":"),
strconv.Itoa(j),
)
}
Expand Down
2 changes: 1 addition & 1 deletion ohgi/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetChecksCheck(api *sensu.API, name string) string {
check, err := api.GetChecksCheck(name)
checkError(err)

table := newUitable()
table := newUitable(true)
table.AddRow(bold("NAME:"), check.Name)
table.AddRow(bold("COMMAND:"), check.Command)
table.AddRow(bold("SUBSCRIBERS:"), strings.Join(check.Subscribers, ", "))
Expand Down
2 changes: 1 addition & 1 deletion ohgi/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GetClientsClient(api *sensu.API, name string) string {
client, err := api.GetClientsClient(name)
checkError(err)

table := newUitable()
table := newUitable(true)
table.AddRow(bold("NAME:"), client.Name)
table.AddRow(bold("ADDRESS:"), client.Address)
table.AddRow(bold("SUBSCRIPTIONS:"), strings.Join(client.Subscriptions, ", "))
Expand Down
6 changes: 3 additions & 3 deletions ohgi/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GetEventsClient(api *sensu.API, client string) string {
table.AddRow(
indicateStatus(event.Check.Status),
event.Check.Name,
strings.Replace(event.Check.Output, "\n", " ", -1),
formatOutput(event.Check.Output),
utoa(event.Check.Executed),
)
}
Expand All @@ -94,7 +94,7 @@ func GetEventsClientCheck(api *sensu.API, client string, check string) string {
event, err := api.GetEventsClientCheck(client, check)
checkError(err)

table := newUitable()
table := newUitable(true)
table.AddRow(bold("CLIENT:"), event.Client.Name)
table.AddRow(bold("ADDRESS:"), event.Client.Address)
table.AddRow(bold("SUBSCRIPTIONS:"), strings.Join(event.Client.Subscriptions, ", "))
Expand All @@ -106,7 +106,7 @@ func GetEventsClientCheck(api *sensu.API, client string, check string) string {
table.AddRow(bold("HANDLERS:"), strings.Join(event.Check.Handlers, ", "))
table.AddRow(bold("ISSUED:"), utoa(event.Check.Issued))
table.AddRow(bold("EXECUTED:"), utoa(event.Check.Executed))
table.AddRow(bold("OUTPUT:"), strings.Replace(event.Check.Output, "\n", " ", -1))
table.AddRow(bold("OUTPUT:"), formatOutput(event.Check.Output))
table.AddRow(bold("STATUS:"), colorStatus(event.Check.Status))
table.AddRow(bold("DURATION:"), strconv.FormatFloat(event.Check.Duration, 'f', 3, 64))
table.AddRow(bold("HISTORY:"), colorHistory(strings.Join(event.Check.History, ", ")))
Expand Down
2 changes: 1 addition & 1 deletion ohgi/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func GetInfo(api *sensu.API) string {
info, err := api.GetInfo()
checkError(err)

table := newUitable()
table := newUitable(true)
table.AddRow(bold("VERSION:"), info.Sensu.Version)
table.AddRow(bold("TRANSPORT:"), strconv.FormatBool(info.Transport.Connected))
table.AddRow(bold("REDIS:"), strconv.FormatBool(info.Redis.Connected))
Expand Down
6 changes: 3 additions & 3 deletions ohgi/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GetResultsClient(api *sensu.API, client string) string {
table.AddRow(
indicateStatus(result.Check.Status),
result.Check.Name,
strings.Replace(result.Check.Output, "\n", " ", -1),
formatOutput(result.Check.Output),
utoa(result.Check.Executed),
)
}
Expand All @@ -92,7 +92,7 @@ func GetResultsClientCheck(api *sensu.API, client string, check string) string {
result, err := api.GetResultsClientCheck(client, check)
checkError(err)

table := newUitable()
table := newUitable(true)
table.AddRow(bold("CLIENT:"), result.Client)
table.AddRow(bold("CHECK:"), result.Check.Name)
table.AddRow(bold("COMMAND:"), result.Check.Command)
Expand All @@ -101,7 +101,7 @@ func GetResultsClientCheck(api *sensu.API, client string, check string) string {
table.AddRow(bold("HANDLERS:"), strings.Join(result.Check.Handlers, ", "))
table.AddRow(bold("ISSUED:"), utoa(result.Check.Issued))
table.AddRow(bold("EXECUTED:"), utoa(result.Check.Executed))
table.AddRow(bold("OUTPUT:"), strings.Replace(result.Check.Output, "\n", " ", -1))
table.AddRow(bold("OUTPUT:"), formatOutput(result.Check.Output))
table.AddRow(bold("STATUS:"), colorStatus(result.Check.Status))
table.AddRow(bold("DURATION:"), strconv.FormatFloat(result.Check.Duration, 'f', 3, 64))

Expand Down
10 changes: 9 additions & 1 deletion ohgi/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"regexp"
"strconv"
"strings"

"github.com/hico-horiuchi/uitable"
)
Expand All @@ -16,13 +17,20 @@ func checkError(err error) {
}
}

func newUitable() *uitable.Table {
func newUitable(wrap ...bool) *uitable.Table {
table := uitable.New()
table.MaxColWidth = uint(terminalWidth / 2)
if wrap != nil && len(wrap) > 0 && wrap[0] {
table.Wrap = true
}

return table
}

func formatOutput(output string) string {
return strings.TrimSpace(strings.Replace(output, "\n", " ", -1))
}

func indicateStatus(status int) string {
if !escapeSequence {
return strconv.Itoa(status)
Expand Down

0 comments on commit 41d15f8

Please sign in to comment.