Merge pull request #265 from dagger/query-formats

dagger query [--format cue|json|text|yaml] (default is json)
This commit is contained in:
Sam Alba
2021-04-02 16:20:39 -07:00
committed by GitHub
4 changed files with 40 additions and 13 deletions

View File

@@ -1,6 +1,8 @@
package compiler
import (
"bytes"
"encoding/json"
"fmt"
"cuelang.org/go/cue"
@@ -135,3 +137,13 @@ func (s JSON) String() string {
}
return string(s)
}
func (s JSON) PrettyString() string {
raw := s.String()
b := &bytes.Buffer{}
// If indenting fails, return raw string
if err := json.Indent(b, []byte(raw), "", " "); err != nil {
return raw
}
return b.String()
}