- Default table output (when stdout is attached to a terminal) stays the same;
- When stdout is redirected, output tab-separated values and no header line;
- With `--json` flag, output structured JSON data.
Example:
$ ghcs list --json
[
{
"Branch": "main",
"Created At": "2021-06-10T15:04:46+02:00",
"Name": "mislav-playground-jvqj",
"Repository": "mislav/playground",
"State": "Shutdown"
},
{
"Branch": "master",
"Created At": "2021-07-15T15:51:08+02:00",
"Name": "mislav-github-github-pwgg365xv",
"Repository": "github/github",
"State": "Shutdown"
}
]
25 lines
343 B
Go
25 lines
343 B
Go
package output
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type tabwriter struct {
|
|
w io.Writer
|
|
}
|
|
|
|
func (j *tabwriter) SetHeader([]string) {}
|
|
|
|
func (j *tabwriter) Append(values []string) {
|
|
var sep string
|
|
for i, v := range values {
|
|
if i == 1 {
|
|
sep = "\t"
|
|
}
|
|
fmt.Fprintf(j.w, "%s%s", sep, v)
|
|
}
|
|
fmt.Fprint(j.w, "\n")
|
|
}
|
|
|
|
func (j *tabwriter) Render() {}
|