Skip to content

Commit 84279ab

Browse files
authored
Add JSON output to info command (#2501)
main: Add json output flag to tinygo info
1 parent a888d62 commit 84279ab

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

main.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"errors"
67
"flag"
78
"fmt"
@@ -1193,8 +1194,10 @@ func main() {
11931194
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
11941195

11951196
var flagJSON, flagDeps, flagTest *bool
1196-
if command == "help" || command == "list" {
1197+
if command == "help" || command == "list" || command == "info" {
11971198
flagJSON = flag.Bool("json", false, "print data in JSON format")
1199+
}
1200+
if command == "help" || command == "list" {
11981201
flagDeps = flag.Bool("deps", false, "supply -deps flag to go list")
11991202
flagTest = flag.Bool("test", false, "supply -test flag to go list")
12001203
}
@@ -1509,14 +1512,37 @@ func main() {
15091512
fmt.Fprintln(os.Stderr, err)
15101513
os.Exit(1)
15111514
}
1512-
fmt.Printf("LLVM triple: %s\n", config.Triple())
1513-
fmt.Printf("GOOS: %s\n", config.GOOS())
1514-
fmt.Printf("GOARCH: %s\n", config.GOARCH())
1515-
fmt.Printf("GOARM: %s\n", config.GOARM())
1516-
fmt.Printf("build tags: %s\n", strings.Join(config.BuildTags(), " "))
1517-
fmt.Printf("garbage collector: %s\n", config.GC())
1518-
fmt.Printf("scheduler: %s\n", config.Scheduler())
1519-
fmt.Printf("cached GOROOT: %s\n", cachedGOROOT)
1515+
if *flagJSON {
1516+
json, _ := json.MarshalIndent(struct {
1517+
GOROOT string `json:"goroot"`
1518+
GOOS string `json:"goos"`
1519+
GOARCH string `json:"goarch"`
1520+
GOARM string `json:"goarm"`
1521+
BuildTags []string `json:"build_tags"`
1522+
GC string `json:"garbage_collector"`
1523+
Scheduler string `json:"scheduler"`
1524+
LLVMTriple string `json:"llvm_triple"`
1525+
}{
1526+
GOROOT: cachedGOROOT,
1527+
GOOS: config.GOOS(),
1528+
GOARCH: config.GOARCH(),
1529+
GOARM: config.GOARM(),
1530+
BuildTags: config.BuildTags(),
1531+
GC: config.GC(),
1532+
Scheduler: config.Scheduler(),
1533+
LLVMTriple: config.Triple(),
1534+
}, "", " ")
1535+
fmt.Println(string(json))
1536+
} else {
1537+
fmt.Printf("LLVM triple: %s\n", config.Triple())
1538+
fmt.Printf("GOOS: %s\n", config.GOOS())
1539+
fmt.Printf("GOARCH: %s\n", config.GOARCH())
1540+
fmt.Printf("GOARM: %s\n", config.GOARM())
1541+
fmt.Printf("build tags: %s\n", strings.Join(config.BuildTags(), " "))
1542+
fmt.Printf("garbage collector: %s\n", config.GC())
1543+
fmt.Printf("scheduler: %s\n", config.Scheduler())
1544+
fmt.Printf("cached GOROOT: %s\n", cachedGOROOT)
1545+
}
15201546
case "list":
15211547
config, err := builder.NewConfig(options)
15221548
if err != nil {

0 commit comments

Comments
 (0)