Merge pull request #255 from sosedoff/pretty-json-default
Pretty-print JSON results by default
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sosedoff/pgweb/pkg/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Row []interface{}
|
type Row []interface{}
|
||||||
@@ -108,7 +110,13 @@ func (res *Result) CSV() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (res *Result) JSON() []byte {
|
func (res *Result) JSON() []byte {
|
||||||
data, _ := json.Marshal(res.Format())
|
var data []byte
|
||||||
|
|
||||||
|
if command.Opts.EnablePrettyJson {
|
||||||
|
data, _ = json.MarshalIndent(res.Format(), "", " ")
|
||||||
|
} else {
|
||||||
|
data, _ = json.Marshal(res.Format())
|
||||||
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type Options struct {
|
|||||||
LockSession bool `long:"lock-session" description:"Lock session to a single database connection" default:"false"`
|
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:""`
|
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:""`
|
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
|
var Opts Options
|
||||||
|
|||||||
Reference in New Issue
Block a user