I am trying to change the output of a subcommand for a CLI plugin but struggling to get it to work correctly. Currently it shows an ugly printed list; I want to format it into a nice table that's easier to read. Without the table, it works fine...just looks ugly. Adding in the table breaks it by saying "....used as a value".
I have tried declaring the line as a string array with no luck. I'm missing something and not sure what.
for {
select {
case <-ticker.C:
stats, _ := ccclient.AppStats(app.Metadata.GUID)
table := ui.Table([]string{"Sample Time", "Instance ID", "CPU %", "Memory (MB)", "Disk (MB)", "Cell IP:port"})
for key, value := range stats {
tickerObject := []string{time.Now().Format(time.RFC3339), key}
//ui.Say(fmt.Sprintf("%s, %s, %s, %s, %s, %s", time.Now().Format(time.RFC3339), key, fmt.Sprintf("%f", value.Stats.Usage.CPU), fmt.Sprintf("%f", (value.Stats.Usage.Mem/1024/1024)), fmt.Sprintf("%f", (value.Stats.Usage.Disk/1024/1024)), value.Stats.Host+":"+strconv.Itoa(value.Stats.Port)))}
table.Add(tickerObject)
table.Print()
}
case <-quit:
ticker.Stop()
}
}
I expect a formatted output that looks cleaner, instead I get -
cannot use tickerObject (type []string) as type string in argument to table.Add
Current output (using the commented out ui.Say line), does not line up:
Collecting stats on app fabric-tasks in space Functions Dev Testing Ctrl-C to stop collection of stats
Sample Time,instance #,cpu %,memory (MB),disk (MB),cell ip:port 2019-06-14T23:33:42-05:00, 0, 0.004659, 38.492188, 205.914062, 169.61.179.187:61440 2019-06-14T23:33:47-05:00, 0, 0.004659, 38.492188, 205.914062, 169.61.179.187:61440 2019-06-14T23:33:52-05:00, 0, 0.004659, 38.492188, 205.914062, 169.61.179.187:61440 2019-06-14T23:33:57-05:00, 0, 0.006533, 38.492188, 205.914062, 169.61.179.187:61440
I don't think the table is the issue, I think I'm just missing something ridiculously simple with how the data is being stored. I think the table can only pull display a string (or at least all the examples of I have found in our internal documentation only call strings).