mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat(cli): add --output={text,json} to version cmd (#7010)
* feat(cliui): add TextFormat * feat(cli): add --format={text,json} to version cmd
This commit is contained in:
@ -3,6 +3,7 @@ package cliui
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@ -171,3 +172,23 @@ func (jsonFormat) Format(_ context.Context, data any) (string, error) {
|
||||
|
||||
return string(outBytes), nil
|
||||
}
|
||||
|
||||
type textFormat struct{}
|
||||
|
||||
var _ OutputFormat = textFormat{}
|
||||
|
||||
// TextFormat is a formatter that just outputs unstructured text.
|
||||
// It uses fmt.Sprintf under the hood.
|
||||
func TextFormat() OutputFormat {
|
||||
return textFormat{}
|
||||
}
|
||||
|
||||
func (textFormat) ID() string {
|
||||
return "text"
|
||||
}
|
||||
|
||||
func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
|
||||
|
||||
func (textFormat) Format(_ context.Context, data any) (string, error) {
|
||||
return fmt.Sprintf("%s", data), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user