dagger query [--format cue|json|text|yaml] (default is json)

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes
2021-04-02 22:47:59 +00:00
parent 11825932cc
commit e2e56a5143
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()
}