Skip to content

Commit bb35fec

Browse files
committed
feat: arg -indent to indent output json
1 parent b3d6331 commit bb35fec

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lang/parse.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type ParseOptions struct {
4141
LSP string
4242
// Language of the repo
4343
Verbose bool
44+
// Whether to indent the output JSON
45+
MarshalIndent bool
4446
collect.CollectOption
4547
}
4648

@@ -81,7 +83,12 @@ func Parse(ctx context.Context, uri string, args ParseOptions) ([]byte, error) {
8183
return nil, err
8284
}
8385
log.Info("all symbols collected, start writing to stdout...\n")
84-
out, err := json.Marshal(repo)
86+
var out []byte
87+
if args.MarshalIndent {
88+
out, err = json.MarshalIndent(repo, "", " ")
89+
} else {
90+
out, err = json.Marshal(repo)
91+
}
8592
if err != nil {
8693
log.Error("Failed to marshal repository: %v\n", err)
8794
return nil, err

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func main() {
9393
flags.BoolVar(&opts.NoNeedComment, "no-need-comment", false, "do not need comment (only works for Go now)")
9494
flags.BoolVar(&opts.NeedTest, "need-test", false, "need parse test files (only works for Go now)")
9595
flags.BoolVar(&opts.CacheResults, "cache", false, "cache language server query results")
96+
flags.BoolVar(&opts.MarshalIndent, "indent", false, "indent the marshaled output")
9697
flags.Var((*StringArray)(&opts.Excludes), "exclude", "exclude files or directories, support multiple values")
9798
flagLsp := flags.String("lsp", "", "Specify the language server path.")
9899

0 commit comments

Comments
 (0)