cliout writes the result of a command for a person and for a program.
A cell often holds text from elsewhere, such as the reason a node gave.
Table escapes each cell with termtext before it measures it, and
WriteJSON escapes the runes that encoding/json leaves as they are.
NODE STATE REASON
exe0001 drained fan failure\nexe0002 idle
exe0003 idle
The newline in the reason cannot start a row that seems to be another.
| Name | What it does |
|---|---|
cliout.Table, cliout.Column | columns aligned by display width; wide columns only for -o wide |
cliout.WriteJSON | JSON with every string safe for a terminal; a slice one element at a time |
table := &cliout.Table{
Columns: []cliout.Column{{Name: "NODE"}, {Name: "CPUS", Right: true}, {Name: "STATE"}, {Name: "REASON", Wide: true}},
Caption: "3 nodes, 1 drained",
}
table.Add("exe0001", "128", "drained", "fan failure\nexe0002 idle")
table.Add("exe0002", "64", "idle")
table.Add("exe10", "8", "idle")
for _, wide := range []bool{false, true} {
if err := table.Write(os.Stdout, wide); err != nil {
fmt.Println(err)
}
fmt.Println("--")
}NODE CPUS STATE
exe0001 128 drained
exe0002 64 idle
exe10 8 idle
3 nodes, 1 drained
--
NODE CPUS STATE REASON
exe0001 128 drained fan failure\nexe0002 idle
exe0002 64 idle
exe10 8 idle
3 nodes, 1 drained
--cliout/example_test.go. CI runs it and checks its output.Fixed interfaces#
What cliout writes (decision 30). The package parses no flag: the
words of -o are the program’s.