Make JSON formatting a feature flag, enabled by default
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sosedoff/pgweb/pkg/command"
|
||||
)
|
||||
|
||||
type Row []interface{}
|
||||
@@ -108,7 +110,13 @@ func (res *Result) CSV() []byte {
|
||||
}
|
||||
|
||||
func (res *Result) JSON() []byte {
|
||||
data, _ := json.MarshalIndent(res.Format(), "", " ")
|
||||
var data []byte
|
||||
|
||||
if command.Opts.EnablePrettyJson {
|
||||
data, _ = json.MarshalIndent(res.Format(), "", " ")
|
||||
} else {
|
||||
data, _ = json.Marshal(res.Format())
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ type Options struct {
|
||||
LockSession bool `long:"lock-session" description:"Lock session to a single database connection" default:"false"`
|
||||
Bookmark string `short:"b" long:"bookmark" description:"Bookmark to use for connection. Bookmark files are stored under $HOME/.pgweb/bookmarks/*.toml" default:""`
|
||||
BookmarksDir string `long:"bookmarks-dir" description:"Overrides default directory for bookmark files to search" default:""`
|
||||
EnablePrettyJson bool `long:"feature-pretty-json" description:"Format JSON output" default:"true"`
|
||||
}
|
||||
|
||||
var Opts Options
|
||||
|
||||
Reference in New Issue
Block a user